【问题标题】:PowerShell remoting session variable isn't workingPowerShell 远程会话变量不起作用
【发布时间】:2019-04-30 21:41:27
【问题描述】:

我正在尝试使用New-PSSession 运行循环并以管理员身份运行,但出现错误。

foreach ($c in $targets) {
    $s = New-PSSession -ComputerName $c -Credential cred
    Invoke-Command -Session $s -ScriptBlock {gci C:\temp} -RunAsAdministrator
}

我收到以下错误:

Invoke-Command : 无法使用指定的命名参数解析参数集。

【问题讨论】:

  • 嗯,是的。如果您查看 Invoke-Command cmdlet 的 documentation,您会发现它没有使用 -Session-RunAsAdministrator 参数设置的参数。
  • 我认为this 可以提供帮助

标签: powershell powershell-remoting


【解决方案1】:

该错误是因为-Session参数不能和-RunAsAdministrator参数同时使用。

【讨论】:

  • 我在尝试使用 ComputerName 参数运行 Invoke-Command cmdlet 时也遇到了同样的错误。使用 RunAsAdministrator 的正确格式是什么?我是UAC环境,所以觉得很有必要。
  • 我认为你只能在本地执行命令时使用它。
猜你喜欢
  • 2016-12-30
  • 2016-01-13
  • 1970-01-01
  • 2013-11-10
  • 2015-09-30
  • 2013-04-12
  • 2012-08-17
  • 2014-05-16
相关资源
最近更新 更多