【问题标题】:Run script on remote computer and pass creds to remote script在远程计算机上运行脚本并将凭据传递给远程脚本
【发布时间】:2020-02-04 20:03:23
【问题描述】:

要求:必须在远程机器上的本地机器上运行,并将凭据传递给远程机器脚本。

$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】:

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

【讨论】:

    猜你喜欢
    • 2015-04-20
    • 1970-01-01
    • 2014-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多