繁体   English   中英

无法在调用Powershell脚本中传递参数

[英]Unable to pass argument in invoke powershell script

我正在尝试在名为install.ps1的以下命令脚本中传递参数值。 我通过./install.ps1 HD1执行它

invoke-command -Session $session -ScriptBlock {G:\usr\sap\$($args[0])\hdbclient\hdbuserstore.exe list}

但这给我一个错误

术语'G:\\ usr \\ sap \\ $($ args [0])\\ hdbclient \\ hdbuserstore.exe'不识别为cmdlet,函数,脚本文件或可运行程序的名称。 检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。 + CategoryInfo:ObjectNotFound:(G:\\ usr \\ sap \\ $($ a ... dbuserstore.exe:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException + PSComputerName:主机名

您没有在Invoke-Command上使用-Argumentlist参数。 让我在下面显示一个例子。 如果要使用自定义变量名称,请在脚本块中使用Param方法。

$Directory = "HD1"
$Scriptblock = {
    param($Var1)
    G:\usr\sap\$Var1\hdbclient\hdbuserstore.exe list
}
invoke-command -Session $session -ScriptBlock $Scriptblock -ArgumentList $Directory

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM