我写了下面的脚本。它工作得很好。但是我错过了重要的一步。评估服务名称是否为:错误/拼写错误。我已经捕获了其中一个拼写错误,并想在我的脚本中添加逻辑来处理它。这是我的脚本。谢谢
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
$Services = Import-Csv '\\wnp6636\d$\Scripts\ProdList(1).csv' | foreach-object {$_}
$ErrorActionPreference = "SilentlyContinue"
foreach ($Serve in $Services) {
get-service -computername $Serve.Server -name $Serve.Services,$Serve.Services_A,$Serve.Services_B,$Serve.Services_C,`
$Serve.Services_D,$Serve.Services_E,$Serve.Services_F,$Serve.Services_G,$Serve.Services_H |`
foreach-object {if($_.Status -eq "Stopped")`
{write-host $Serve.Server $_.Displayname $_.Status -Fore "Red"}
else
{write-host $Serve.Server $_.Displayname $_.Status -Fore "Green"}
}
}