[英]Unable to pass argument in invoke powershell script
I am trying to pass value for argument in below command script called install.ps1. 我正在尝试在名为install.ps1的以下命令脚本中传递参数值。 I execute it by ./install.ps1 HD1
我通过./install.ps1 HD1执行它
invoke-command -Session $session -ScriptBlock {G:\usr\sap\$($args[0])\hdbclient\hdbuserstore.exe list}
but it gave an error to me that 但这给我一个错误
The term 'G:\\usr\\sap\\$($args[0])\\hdbclient\\hdbuserstore.exe' is not recognized as the name of a cmdlet, function, script file, or operable program.
术语'G:\\ usr \\ sap \\ $($ args [0])\\ hdbclient \\ hdbuserstore.exe'不识别为cmdlet,函数,脚本文件或可运行程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。 + CategoryInfo : ObjectNotFound: (G:\\usr\\sap\\$($a...dbuserstore.exe:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException + PSComputerName : hostname
+ CategoryInfo:ObjectNotFound:(G:\\ usr \\ sap \\ $($ a ... dbuserstore.exe:String)[],CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException + PSComputerName:主机名
You are not using the -Argumentlist
parameter on Invoke-Command
. 您没有在
Invoke-Command
上使用-Argumentlist
参数。 Let me show an example below. 让我在下面显示一个例子。 Use the Param method inside the scriptblock if you want to use custom variable names.
如果要使用自定义变量名称,请在脚本块中使用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.