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.
$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:
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
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?
Start-Process 'C:\windows\system32\notepad.exe' -Credential $cred