【问题标题】:Remote Powershell Install Issue远程 Powershell 安装问题
【发布时间】:2015-02-18 23:21:14
【问题描述】:

我正在尝试使用 powershell 远程自动化安装,并且我有多个工作,最后一个不工作是在我远程进入之后,我复制文件很好,但是当我尝试执行 PS 脚本时,我失败了同样的错误。脚本和错误如下:

Enable-WSManCredSSP -Role Client -DelegateComputer $SQL_Server -Force 
 $cred = New-Object -TypeName System.Management.Automation.PSCredential $Secure_SQLInstaller, $Secure_SQLInstallerPassword

 $Batch_exec = "\\demo.dev\SI\Start.ps1"

 $Argument_list = "$SV, $SE, $DC, $SA, $SP, $SAP, $FP, $DT, $PSN, $E"

 Invoke-Command -ComputerName $SQL_Server -Authentication CredSSP -credential $cred -FilePath $Batch_exec -scriptblock { Start-Process -FilePath $Batch_exec -ArgumentList $Argument_list }


Invoke-Command : Parameter set cannot be resolved using the specified named parameters.
At line:110 char:2
+  Invoke-Command -ComputerName $SQL_Server -Authentication CredSSP -credential $c ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand

【问题讨论】:

  • 另外,我知道 Argument_list 有数组的逗号,但即使我因为调用函数而将它们取出,我也会得到同样的错误。只是想记下这一点。感谢您的帮助。
  • 很确定这是因为您使用的是-FilePath -scriptblock

标签: powershell remote-access


【解决方案1】:

我很确定它告诉您这是一个模棱两可的参数集,因为您已经指定了 -FilePath 和 -Sciptblock。你必须选择一个或另一个,所以:

Invoke-Command -ComputerName $SQL_Server -Authentication CredSSP -credential $cred  -scriptblock { Start-Process -FilePath $Batch_exec -ArgumentList $Argument_list }

Invoke-Command -ComputerName $SQL_Server -Authentication CredSSP -credential $cred -FilePath $Batch_exec

有关更多信息,请查看Invoke-Command 的参数集。你会发现它们是相互排斥的。

【讨论】:

  • 我尝试了第一个选项,我得到:无法验证参数“文件路径”上的参数。参数为 null 或空。提供一个不为 null 或空的参数,然后重试该命令。
  • 尝试了第二个选项并得到:我尝试了第一个选项并得到:无法将参数绑定到参数“路径”,因为它为空; '.' 之后的表达式在管道元素中生成了一个无效的对象。它必须产生一个命令名称、一个脚本块或一个 CommandInfo 对象。这可能是因为我要去另一个域。
  • 尝试使用单引号创建该字符串,如下所示: $Batch_exec = '\\demo.dev\SI\Start.ps1' ?
  • 另外,您可能会在尝试像这样在脚本块中使用 $Batch_exec 时遇到范围问题。
  • 试过单引号,但没有用,同样的错误。在脚本块中有 $Batch_exec 并收到错误 Cannot validate argument on parameter 'FilePath'。
猜你喜欢
  • 2020-07-21
  • 2015-12-08
  • 1970-01-01
  • 1970-01-01
  • 2014-03-12
  • 2015-07-06
  • 2022-10-22
  • 2021-07-05
  • 1970-01-01
相关资源
最近更新 更多