0
我需要能夠在另一臺服務器上運行命令。該腳本充當在實際服務器上運行的另一個腳本的引導程序。這在同一個域上的服務器上效果很好,但如果我需要在遠程服務器上運行此腳本,則需要指定憑據。Powershell調用命令與PSCredential在行
的命令是從的MSBuild目標拉開序幕文件中像這樣:
<Target Name="PreDeployment" Condition="true" BeforeTargets="MSDeployPublish">
<Exec Command="powershell.exe -ExecutionPolicy Bypass invoke-command bootstrapScript.ps1 -computername $(MyServer) -argumentlist param1, param2" />
</Target>
不過,我需要能夠通過創建一個新的PSCredentials提供的憑據,我的部署腳本到一個安全的密碼對象在遠程服務器上運行:
<Target Name="PreDeployment" Condition="true" BeforeTargets="MSDeployPublish">
<Exec Command="powershell.exe -ExecutionPolicy Bypass invoke-command bootstrapScript.ps1 -computername $(MyServer) -credential New-Object System.Management.Automation.PSCredential ('admin', (convertto-securestring $(Password) -asplaintext -force)) -argumentlist param1, param2" />
</Target>
當我運行構建,彈出一個對話框,設置爲System.Management.Automation.PSCredential的用戶名。 我需要能夠在可執行目標上聯機創建憑據。我該如何做到這一點?