在远程计算机上运行脚本并将凭据传递给远程脚本

问题描述 投票:0回答:1

要求:必须在凭据传递到远程计算机脚本的情况下从远程计算机上的本地计算机运行。

$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)
powershell-4.0 powershell-remoting
1个回答
0
投票

如果不将其传递为参数,则不能在另一台计算机上的scriptBlock中使用Variable $ credentials:Pass arguments to a scriptblock in powershell

© www.soinside.com 2019 - 2024. All rights reserved.