我正在为我管理的某些服务器创建报告。
我在报告中还有很多其他信息,这些信息已经有了我想要的,但是这困扰了我一段时间-无论我做什么以及在哪里搜索,我都无法解决问题。
以下代码检查我的7台服务器中是否有任何以“ Office Comm”开头的已停止服务,并显示在HTML表中已停止的所有服务,但是它只会输出所有已停止服务的第一个,而不是整个列表...我有搜索并重新编码,并尝试了不同的方法,但仍无法解决....任何帮助将不胜感激!
Write-Host "Getting stopped services snapshot...`n"
$StoppedServicesReport = @()
$StoppedServices = Get-WmiObject -Class Win32_Service -ComputerName $Computers `
-Filter "displayname like 'Office Comm%' AND state='Stopped'"
foreach ($StoppedService in $StoppedServices) {
$stoppedRow = New-Object -Type PSObject -Property @{
Server = $StoppedService.SystemName
Name = $StoppedService.DisplayName
Status = $StoppedService.State
}
$StoppedServiceReport = $StoppedServiceReport + $stoppedRow
}
$StoppedServiceReport = $StoppedServiceReport | ConvertTo-Html -Fragment
这是另一种方法:
$computers | Foreach-Object {
$computerName = $_
Get-Service -ComputerName $computerName -DisplayName "Office Comm*" |
Where-Object { $_.Status -eq "Stopped" } |
Select-Object @{ n = "Server"; e = { $computerName } }, @{ n = "Name"; e = { $_.DisplayName } }, Status
} | ConvertTo-Html -Fragment
有关您的原始错误,请参阅PetSerAl的评论。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句