要求:必须在凭据传递到远程计算机脚本的情况下从远程计算机上的本地计算机运行。
$server = 'SRV1'
$credential = Get-Credential
$credentials = Get-Credential
Invoke-Command -ComputerName $server -Credential $credential -ScriptBlock {
C:\foo.ps1 $credentials
}
foo.ps1需要使用需要$ credentials的函数
在foo.ps1内部
param($credentials)
答案 0 :(得分:0)
如果不将其作为参数传递,则不能在另一台计算机上的scriptBlock中使用Variable $ credentials: Pass arguments to a scriptblock in powershell