jaf*_*ffa 1 powershell powershell-2.0
我需要能够在另一台服务器上运行命令。此脚本充当在实际服务器上运行的另一个脚本的引导程序。这在同一个域上的服务器上效果很好,但是如果我需要在远程服务器上运行这个脚本,我需要指定凭据。
该命令从 Msbuild 目标文件中启动,如下所示:
<Target Name="PreDeployment" Condition="true" BeforeTargets="MSDeployPublish">
<Exec Command="powershell.exe -ExecutionPolicy Bypass invoke-command bootstrapScript.ps1 -computername $(MyServer) -argumentlist param1, param2" />
</Target>
Run Code Online (Sandbox Code Playgroud)
但是,我需要能够通过使用安全密码创建新的 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>
Run Code Online (Sandbox Code Playgroud)
当我运行构建时,会弹出一个对话框,用户名设置为 System.Management.Automation.PSCredential。我需要能够在可执行目标上在线创建凭据。我该如何实现?
尝试在 PSCredential 对象的实例化周围放置括号,例如:
... -credential (New-Object System.Management.Automation.PSCredential 'admin',(convertto-securestring $(Password) -asplaintext -force)) -argumentlist param1, param2" />
Run Code Online (Sandbox Code Playgroud)
PowerShell 解析倾向于将参数解释为文字字符串(或数字)。如果要计算表达式,通常将表达式放在括号内。这在 PowerShell 中称为分组表达式。
| 归档时间: |
|
| 查看次数: |
3634 次 |
| 最近记录: |