当从splunk系统执行下面的代码时,我们会在日志文件中返回以下错误:
错误用户脚本异常::无法绑定参数'FilterScript'。无法将“System.String”类型的“Name”值转换为“System.Management.Automation.ScriptBlock”类型。
它似乎不喜欢Name
条款中的where
变量,无论如何要解决这个问题?
Get-WmiObject –class win32_process |
Add-Member -MemberType ScriptProperty -PassThru -Name Username -Value {$ud= $this.GetOwner();$user=$ud.Domain+"\"+$ud.User;
if ($user -eq "\") {"SYSTEM"} else {$user}} |
where Name -eq "splunkd.exe" |
where Username -ne "NT AUTHORITY\SYSTEM" |
Format-List -Property Name, KernelModeTime, UserModeTime, ProcessID, WorkingSetSize, PageFileUsage, PageFaults
你有旧版本的PowerShell,其中Where-Object
期待一个代码块,并试图将Name
视为一个。请改用此格式:
Where-Object { $_.Name -eq "splunkd.exe" } |