Powershell - Masking a line with secure string causing -
to log something, have enter username on page1, password on page2, click submit on page3. make easier wrote ps script. double checked hard-coding password, , successful.
but not wanting hard-code password used added $pass
, how read it. invalid password when run script.
i wanted use get-credentials
, didn't know how pass in username or password on specific pages.
i appreciate advice me in right direction towards goal.
$pass = read-host 'd\p password?' -assecurestring [runtime.interopservices.marshal]::ptrtostringauto( [runtime.interopservices.marshal]::securestringtobstr($pass)) $ie = new-object -comobject internetexplorer.application $url = 'https://website/' $ie.visible = $true $ie.navigate($url) while ($ie.busy -eq $true) {start-sleep -milliseconds 1000} $ie.document.getelementbyid('data').value = "p0523586" $submit = $ie.document.getelementsbytagname('input') | ? {$_.type -eq "submit"} $submit.click() while ($ie.busy -eq $true) {start-sleep -milliseconds 1000} $ie.document.getelementbyid('data').value = "$pass" $submit = $ie.document.getelementsbytagname('input') | ? {$_.type -eq "submit"} $submit.click() while ($ie.busy -eq $true) {start-sleep -milliseconds 1000} $submit = $ie.document.getelementsbytagname('input') | ? {$_.type -eq "submit"} $submit.click()
get-credential
way go aren't storing should kept secure in script.
it's easiest assign object returned get-credentials
variable:
$credentials = get-credential
you can use $credentials.username
retrieve username:
ps> $credentials.username myusername
and $credentials.password
retrieve secure password object
ps> $credentials.password system.security.securestring
this can used other powershell commands, needs decoded (made un-secure) before can sent process cannot accept secure password objects.
to retrieve password in plain-text, can use getnetworkcredential
method this:
ps> $credentials.getnetworkcredential().password mypassword
in script add $credentials = get-credential
@ start of script, , submit username/password form this:
$ie.document.getelementbyid('data').value = $credentials.username $ie.document.getelementbyid('data').value = $credentials.getnetworkcredential().password
Comments
Post a Comment