我有一个场景,我需要检查大约100个windows服务,无论它们是否被禁用。
我有一个解决方案,可以单独检查"disabled“的服务启动类型,比如
if(((Get-Service -Name ServiceName).StartType -eq "Disabled")-and((Get-Service -Name ServiceName).Status -eq "Stopped")){
Write-Output "Service disabled"
} else {
Write-Output "Service not disabled"
}
除了单独检查之外,还有其他方法可以一次性检查服务吗?
发布于 2019-08-01 15:49:05
试试这个:
$ServicesName='tzautoupdate', 'shpamsvc'
Get-Service -Name $ServicesName | Where Status -eq "Stopped" | %{
"Service {0} is '{1}'" -f $_.Name, $_.StartType
}
发布于 2019-08-01 11:53:45
下面这句简单的话很适合你
Get-Service | Where-Object { $_.StartType -eq "Disabled" -and $_.Status -eq "Stopped" } | Select -Property "Name"
它会给你一个被禁用和停止的服务列表。
https://stackoverflow.com/questions/57301156
复制相似问题