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

无法在调用powershell脚本中传递参数,powershell,powershell-3.0,Powershell,Powershell 3.0,我试图在下面名为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、函数、脚本文件或文件的名称

我试图在下面名为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命令
上使用
-Argumentlist
参数。下面让我举一个例子。如果要使用自定义变量名,请在scriptblock中使用Param方法

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

您没有在
Invoke命令
上使用
-Argumentlist
参数。下面让我举一个例子。如果要使用自定义变量名,请在scriptblock中使用Param方法

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

($args[0])
应该包含什么?它是作为字符串文本传递的,而不是扩展变量,因此操作系统正在寻找错误的路径。它应该接受我作为install.ps1参数传递的HD1值。什么
($args[0])
应该包含?它作为字符串文本而不是扩展变量传递,因此操作系统正在寻找错误的路径。它应该接受HD1值,我将其作为install.ps1的参数传递。