问题
I have come across a rare occurrence as this cannot be replicated on my own machine however on one of our Windows Server 2012 instances it occurs.
The script I invoke looks like this
$arg="D:\Scripts\test.ps1"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Start-Process -FilePath powershell.exe -Credential $Credential -ArgumentList $arg
This piece of code just hangs on the server while this
$arg="D:\Scripts\test.ps1"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Start-Process -FilePath powershell.exe -ArgumentList $arg
runs just fine, the test.ps1 script only contains the following so it should not be breaking since it works normally but just with the seperate user credential it does not work.
write-host "Output:"
write-host ""
Write-Host ("----------------------------------------------------------------")
Also I have tested using my user credentials even instead of our service user and i get the same issue so it seems to be an issue with Start-Process itself when ran with the -Credential verb.
If anyone has dealt with this before any help would be greatly appreciated. I have also tried changing the execution policy on the server to remote signed but also to no avail.
来源:https://stackoverflow.com/questions/41934674/running-powershell-start-process-with-credential-makes-script-hang-windows-ser