Powershell - 按多个名称过滤 WMIObject 进程
我正在尝试获取正在运行的进程的列表并按两个进程名称进行过滤 - 谁能告诉我如何使其正常工作?
到目前为止,我已经可以正常工作并过滤掉一个进程名称:
$rn = Get-WMIObject Win32_Process -computer servername `
-credential mydomain\administrator -filter "Name='program1.exe'" |
select -expand path
$lst = Get-Content “C:\path\path2\List.txt”
Compare-Object $lst $rn
我想要它做的是过滤两个进程名称,但我尝试过的任何方法都不起作用。有什么想法吗?
I am trying to get a list of running processes and filter by two process names - can any one tell me how to get this working?
I've so far got it working and filtering out one process name:
$rn = Get-WMIObject Win32_Process -computer servername `
-credential mydomain\administrator -filter "Name='program1.exe'" |
select -expand path
$lst = Get-Content “C:\path\path2\List.txt”
Compare-Object $lst $rn
What I want it to do is filter two process names but nothing I've tried works. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 WQL 运算符,如 OR、AND、LIKE 等:
Use WQL operators like OR, AND, LIKE etc:
以下是如何获取与您感兴趣的进程名称列表相匹配的完整 Process 对象集。
此示例查找所有进程,然后通过将它们发送到管道过滤器来过滤该列表,管道过滤器检查是否包含进程名称在有趣的进程名称列表中。以这种方式使用管道的主要好处是您可以轻松访问返回进程的其他属性(例如 ProcessID)。
Here's how to get a complete set of Process objects which match a list of process names you're interested in.
This example finds all processes, then filters that list by sending them to a pipeline filter that checks to see if the process name is contained in the list of interesting process names. The main benefit of using the pipeline this way is that you can easily access other attributes (such as ProcessID) of the returned processes.
创建您要处理的进程的数组:
我已经注释掉了您的比较,以便您可以清楚地看到我们如何循环遍历该数组。
Create an array of the processes you're after:
I've commented out your compare so you can see how we are looping through the array clearly.
如果我理解得很好试试这个:
if I understood well try this: