Hello, I am just beginning my powershell adventures and I am having a few issues.
I have written the below script to go out to a List of Servers and check the status for only these specific windows Services to do a validation that they are running after a reboot or otehr maintenance. I am using the Get-Service cmdlt as shown below. I am sure there is an easier way to do this however this fits my needs at the moment. I want the output in an HTML file. The problem I am trying to solve is this, when the status comes back I would like it to return in either GREEN if the status is "Running" and RED if the Status is "Stopped".
Again I am sure there is a simpler way to achieve this with less lines but here is the script that I have now any help or advice will be greatly appreciated:
$Style = "<style>"
$Style = $Style + "BODY{background-color:#D7D8D8;}"
$Style = $Style + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$Style = $Style + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$Style = $Style + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$Style = $Style + "</style>"
$ServerList = Get-Content -path B:MYSHAREPowershellScriptscomputers.txt
$a = $ServerList | foreach { (Get-Service -Name IISADMIN -computername $_) | Select-Object MachineName, Name, DisplayName, Status | ConvertTo-HTML -Fragment}
$b = $ServerList | foreach { (Get-Service -Name W3SVC -computername $_) | Select-Object MachineName, Name, DisplayName, Status | ConvertTo-HTML -Fragment }
$c = $ServerList | foreach { (Get-Service -Name HTTPFilter -computername $_) | Select-Object MachineName, Name, DisplayName, Status | ConvertTo-HTML -Fragment}
$d = $ServerList | foreach { (Get-Service -Name cpsvc -computername $_) | Select-Object MachineName, Name, DisplayName, Status | ConvertTo-HTML -Fragment}
$e = $ServerList | foreach { (Get-Service -Name CitrixWMIService -computername $_) | Select-Object MachineName, Name, DisplayName, Status | ConvertTo-HTML -Fragment}
$f = $ServerList | foreach { (Get-Service -Name CtxHttp -computername $_) | Select-Object MachineName, Name, DisplayName, Status | ConvertTo-HTML -Fragment}
$g = $ServerList | foreach { (Get-Service -Name CitrixXTEServer -computername $_) | Select-Object MachineName, Name, DisplayName, Status | ConvertTo-HTML -Fragment}
$h = $ServerList | foreach { (Get-Service -Name IMAService -computername $_) | Select-Object MachineName, Name, DisplayName, Status | ConvertTo-HTML -Fragment}
$i = $ServerList | foreach { (Get-Service -Name CdmService -computername $_) | Select-Object MachineName, Name, DisplayName, Status | ConvertTo-HTML -Fragment}
$j = $ServerList | foreach { (Get-Service -Name "Citrix SMA Service" -computername $_) | Select-Object MachineName, Name, DisplayName, Status | ConvertTo-HTML -Fragment}
ConvertTo-HTML -head $Style -body "<H2>Validation Completed</H2> $a $b $c $d $e $f $g $h $i $j" | Out-File "B:MYSHAREPowershellScriptsValidated.htm"