encrypt and decrypt password in PS won't work as scheduled batch file, runs fine from commnad line


i have alerting program can run batch file if trigger condition met.  use batch file run ps script.  because there logins involved, saved password local text file.  use get-content , convert text file secure string (convertto-securestring); this:


$pwd = get-content d:\bat\pwd.txt | convertto-securestring

$pwd2 = [runtime.interopservices.marshal]::ptrtostringauto([runtime.interopservices.marshal]::securestringtobstr($pwd))

later on call exe has parameter password (-password $pwd2).

when run batch file command prompt executes ps script correctly.  hangs @ first line uses decrypted password when triggered through alerting program.  can tell because of what's showing in task manager (i can kill exe process requires password , script continue).  if remove ecrypted password process , use clear text string (what wanted avoid in first place), works. 

any ideas why password encrypt/decrypt might not work through batch file?  main thing needed change converting ps script batch friendly use full path names (the password file, exe, etc).  need load type of runtime password decrypt?

i figured out problem.  the alerting application runs the script nt authority local system account.  password text file was  created under different user account.  apparently there security key associated password file creator can decrypt.  logged in system account using psexec and regenerated password text file , script runs way through when triggered alerting application.


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group