0

我有这个脚本,它检查多个服务器是否运行特定的服务。

我需要关于如何让它不拉回运行/不运行响应的帮助或指示。我需要让它成为“如果所有查询的服务都在运行 = OK,如果没有列出服务未运行”

这是可行的吗?

脚本:

$Check1 = Get-service -Computername server1 -Name *service1* | ConvertTo-Html Name,Status -Fragment
$Check2 = Get-Service  -Computername server2 -name *service2* | ConvertTo-Html Name,Status  
$Check3 = Get-Service  -Computername server3 -name *service3* | ConvertTo-Html Name,Status
$Check4 = Get-Service -ComputerName UKVAULT01 -Name *service4* | ConvertTo-Html Name,Status
ConvertTo-HTML -Body "<b>Check1</b> $Check1 <br> <b>Check2</b> $Check2 <br> <b>Check3</b> $Check3<br> <b>Check4</b> $Check4" -Title "Service Checks" | Out-File c:\StatusReport.html
4

1 回答 1

1

将检查封装在这样的函数中:

function Check-Service{$server, $name) {
  $check = Get-Service $server -Name $name | ? { $_.Status -ne "Running" }
  if ( $check -eq $null ) { $check = "OK" }
  $check | ConvertTo-Html -Fragment
}

$Check1 = Check-Service server1 *service1*
$Check2 = Check-Service server2 *service2*
...
于 2013-05-15T11:10:50.170 回答