我正在尝试使用附加脚本将参数传递给远程计算机。但它抛出异常说:"无法索引到null数组"。我哪里错了?
param(
[Parameter(Mandatory = $True, Position = 0)][ValidateNotNull()]$server = $(throw "Please provide Environment name. Ex: cyclone,jwoww or joker"),
[Parameter(Mandatory = $true, position = 1)][string]$logType = $(throw "Please provide type of log you want"),
[Parameter(Mandatory = $true, position = 2)][string]$howMany = $(throw "Please provide number of log rows you want")
)
invoke-command -computername $server -credential abc\def{
Get-EventLog -logname $arg[0] -newest $arg[1] | Out-File c:\EventLogs.txt
} -argumentlist $logType,$howMany
答案 0 :(得分:1)
只需将Param
块添加到Invoke-Command cmdlet,然后使用参数名称而不是$arg[0]
和$arg[1]
invoke-command -computername $server -credential abc\def{
Param($logType, $howMany)
Get-EventLog -logname $logType -newest $howMany | Out-File c:\EventLogs.txt
} -argumentlist $logType,$howMany