Powershell合并结果


支持所有PS版本

让我们假设你想要找出可疑的服务状态,如停止的服务但它的模式为“自动”或服务为异常的退出代码。

这里有一段代码例子教你怎么去查询它们的结果并整理输出到一个变量。

Sort-Object 能让你排除掉输出前列表容器中重复的对象并输出到一个视窗中。

$list = @()

$list += Get-WmiObject -Class Win32_Service -Filter 'State="Stopped" and StartMode="Auto" and ExitCode!=0' | 
  Select-Object -Property Name, DisplayName, ExitCode, Description, PathName, DesktopInteract 

$list += Get-WmiObject -Class Win32_Service -Filter 'ExitCode!=0 and ExitCode!=1077' | 
  Select-Object -Property Name, DisplayName, ExitCode, Description, PathName, DesktopInteract 


$list |
  # remove identical (-Unique)
  Sort-Object -Unique -Property Name | 
  Out-GridView

原文地址:Combining Results

本文链接: https://www.pstips.net/combining-results.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注