【发布时间】:2016-06-30 06:54:58
【问题描述】:
我想使用 PowerShell 脚本调用位于服务器上的 VBScript,我想使用 invoke-command 在 VBS 中传递参数。
代码:
$username = [Environment]::UserName # Get the current user name
# Get with a Credential the logins to connect to an AS400 Server
$credential = $host.ui.PromptForCredential("Login", "Please enter your ID.", "", "")
$ASUser = $credential.Username.Substring(1)
$ASPwrd = $credential.GetNetworkCredential().password
# Call of the VBS on the server with these parameters
Invoke-Command -ComputerName MyServerName -ScriptBlock {
CSCRIPT "C:\MyScript.vbs"
} -ArgumentList $username, $ASUser, $ASpwrd
但是我遇到了一个由 VBS 中的参数引起的问题,在这些行:
User = WScript.Arguments(0)
UID = WScript.Arguments(1)
PWD = WScript.Arguments(2)
PowerShell 脚本返回此错误:
C:\MyScript.vbs(64, 1) Microsoft VBScript 运行时错误:下标超出范围
+ CategoryInfo : NotSpecified: (C:\Excel Script...pt out of range:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
第 64 行是User = WScript.Arguments(0)。
好像我的VBS不识别我传参数,所以我认为问题出在PS脚本上,我也试过这样传参数:
Invoke-Command -ComputerName MyServerName -ScriptBlock {
CSCRIPT "C:\MyScript.vbs" $username $ASUser $ASpwrd
}
它不起作用。
【问题讨论】:
标签: powershell vbscript