Question:
I have a script to start another ps1 script as aspecific user that does a simple dir on a directory and it works, when it runs a separate cmd window appears with the directory contents.
1 2 3 4 5 6 7 8 |
$encpwd = Get-Content C:\path\to\creds.txt $passwd = ConvertTo-SecureString $encpwd $cred = new-object System.Management.Automation.PSCredential 'theuser',$passwd Start-Process c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -Credential $cred -ArgumentList '-noexit','-File', 'C:\path\to\script\test.ps1' |
My goal is to start an application as a specific user. So first I wanted to test with notepad.exe So I changed the last line to:
1 2 |
Start-Process c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -Credential $cred -ArgumentList '-noexit','-File', 'C:\windows\system32\notepad.exe' |
All I get is a command window that quickly disappears, can’t tell if there is an error etc. I also tried calling a ps1 script that invoked notepad and got the same result, even though on its own the the new script invoked notepad just fine.
Can someone explain where I am going wrong, Thanks
Answer:
If you’re wanting to start an application, wouldn’t you just use that as the target of Start-Process instead of opening another PowerShell window to do it?
1 2 |
Start-Process 'C:\windows\system32\notepad.exe' -Credential $cred |