Running Powershell Start-Process With -Credential makes script hang (Windows Server 2012)

女生的网名这么多〃 提交于 2019-12-12 04:37:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!