简体   繁体   English

从命令行错误中调用Powershell脚本

[英]calling powershell script from command line error

when executing the code below from the splunk system we get the following error coming back in the log file: 从splunk系统执行以下代码时,我们在日志文件中返回以下错误:

ERROR User script exception: : Cannot bind parameter 'FilterScript'. 错误用户脚本异常::无法绑定参数“ FilterScript”。 Cannot convert the "Name" value of type "System.String" to type "System.Management.Automation.ScriptBlock". 无法将类型“ System.String”的“名称”值转换为类型“ System.Management.Automation.ScriptBlock”。

It seems to be not liking the Name variable in the where clause, is there anyway to get around this? 似乎不喜欢where子句中的Name变量,是否有解决方法?

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

You have older version of PowerShell, where Where-Object is expecting a code block and tries to treat the Name as one. 您使用的是旧版PowerShell,其中Where-Object需要一个代码块,并尝试将Name视为一个。 Use this format instead: 请改用以下格式:

Where-Object { $_.Name -eq "splunkd.exe" } |

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM