我正在编写一个脚本来连接远程服务器并获取日志。
这是woking:
foreach ($serv in $server) {
Invoke-Command {
Get-WinEvent -FilterHashtable @{
logname = 'application';
starttime = '18/08/2017 10:00:00'
}
} -Credential $cred -ComputerName $serv
}
但是当我尝试传递如下动态值时:
$application = "Application"
foreach ($serv in $server) {
Invoke-Command {
Get-WinEvent -FilterHashtable @{
logname = $application;
starttime = '18/08/2017 10:00:00'
}
} -Credential $cred -ComputerName $serv
}
显示错误:
A null value was encountered in the logname hash table key. Null values are not permitted. + CategoryInfo : InvalidArgument: (logname:String) [Get-WinEvent], Exception + FullyQualifiedErrorId : NullNotAllowedInHashtable,Microsoft.PowerShell.Commands.GetWinEventCommand