从`wmic service get`命令中过滤Microsoft服务

问题描述 投票:1回答:1

我正在使用wmic枚举已安装的服务:

wmic service get

是否可以从中隐藏Microsoft服务?

查询返回以下字段,它们似乎都没有帮助:

AcceptPause AcceptStop Caption CheckPoint CreationClassName Description DesktopInteract DisplayName ErrorControl ExitCode InstallDate Name PathName ProcessId ServiceSpecificExitCode ServiceType Started StartMode StartName State Status SystemCreationClassName SystemName TagId WaitHint
wmic
1个回答
0
投票

此命令可以解决问题:

WMIC service where "Not PathName like '%Micro%' AND Not PathName like '%Windows%'" get Name, DisplayName, PathName, Status

而且您也可以使用Powershell脚本来完成它:

在此处参考此答案How to filter Microsoft Service using PowerShell?

您可以使用powershell脚本过滤非Microsoft服务,>

$services = Get-WmiObject Win32_Service -Property Name,DisplayName,PathName | Select Name, DisplayName,PathName
$serviceList = New-Object System.Collections.ArrayList
foreach ($service in $services) {
  Try {
    $path = $service.Pathname.tostring().replace('"','')
    $cri = ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($path)).legalcopyright
    if ($cri -notlike "*Microsoft*") {
      $serviceList += $service
    }
  } catch {}
}
$serviceList
© www.soinside.com 2019 - 2024. All rights reserved.