Phrasing data from power shell


$ServerListFile = "C:\Servers.txt"  
$ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue 
$Result = @() 
ForEach($computername in $ServerList) 
{

$AVGProc = Get-WmiObject -computername $computername win32_processor | 
Measure-Object -property LoadPercentage -Average | Select Average
$OS = gwmi -Class win32_operatingsystem -computername $computername |
Select-Object @{Name = "MemoryUsage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
$vol = Get-WmiObject -Class win32_Volume -ComputerName $computername -Filter "DriveLetter = 'C:'" |
Select-object @{Name = "C PercentFree"; Expression = {“{0:N2}” -f  (($_.FreeSpace / $_.Capacity)*100) } }

$operatingSystem = Get-WmiObject -computername $computername Win32_Service | where {$_.Name -eq "ALG"} | select-object Name, State 

$result += [PSCustomObject] @{ 
    ServerName = "$computername"
    CPULoad = "$($AVGProc.Average)%"
    MemLoad = "$($OS.MemoryUsage)%"
    CDrive = "$($vol.'C PercentFree')%"
    Uptime = "$operatingsystem"
}
$Outputreport = "<HTML><TITLE> Loftware Health Report </TITLE>
                 <BODY background-color:peachpuff>
                 <font color =""#99000"" face=""Microsoft Tai le"">
                 <H2> Server Health Check </H2></font>
                 <Table border="1">
                 <TR align="center">
                   <TD><B>Server Name</B></TD>
                   <TD><B>Avrg.CPU Utilization</B></TD>
                   <TD><B>Memory Utilization</B></TD>
                   <TD><B>Drive C Free Space</B></TD>
                   <TD><B>Service</B></TD>
                   </TR>"

Foreach($Entry in $Result) 

    { 
      if(($Entry.CpuLoad) -or ($Entry.memload) -ge "80") 
      { 
        $Outputreport += "<TR>" 
      } 
      else
       {
        $Outputreport += "<TR>" 
      }
      $Outputreport += "<TD>$($Entry.Servername)</TD><TD align="center">$($Entry.CPULoad)</TD><TD align="center">$($Entry.MemLoad)</TD><TD align="center">$($Entry.CDrive)</TD><TD align="leftr">$($Entry.Uptime)</TD></TR>" 
    }
 $Outputreport += "</Table></BODY></HTML>" 
    } 

$Outputreport | out-file "C:\test.html"

Jimmy, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

When you post code, error messages, sample data or console output format it as code, please. In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.

Thanks in advance.

thanks man my question is how can i remove @{Name=ALG; State=Stopped} to just say Stopped

Are you referring to this line?

$operatingSystem = Get-WmiObject -computername $computername Win32_Service | where {$_.Name -eq "ALG"} | select-object Name, State 

I don’t see @{Name=ALG; State=Stopped}. It’s odd that the variable is called operatingsystem when it’s really collecting services. If you’re just wanting a list of all services that are stopped, this may be better.

Get-Service -computername $computername | Where-Object {$_.Status -eq 'stopped'} | Select-Object name, status

You could also get the display name as it’s usually more human friendly. Another consideration is if it’s set to automatic, manual, or disabled. Do you really want to know the services that are stopped if they are set to disabled? Also, you can break the lines at the | pipe character to improve readability. Lastly, you may also want to sort them further. This command may be more useful.

Get-Service -computername $computername |
    Where-Object {$_.StartType -ne 'disabled' -and $_.Status -eq 'stopped'} |
        Select-Object Displayname, name, Starttype, status | Sort-Object -Property starttype, displayname

After rereading I’m starting to think you are wanting the status of just the ALG service, and you want the output (that you haven’t shown) to only list Stopped instead of @{Name=ALG; State=Stopped} If this is the case, change your line to this.

$operatingSystem = Get-WmiObject -computername $computername Win32_Service | where {$_.Name -eq "ALG"} | select-object -expandproperty state

I still recommend renaming the variables to what they are actually for, so that you don’t confuse yourself or others down the road. I’d also encourage you to either use Get-Service or Get-CimInstance

$ALGServiceState = Get-Service -computername $computername | where-object name -like "*alg*" | Select-Object -ExpandProperty status
OR
$ALGServiceState = Get-CimInstance -CimSession $computername -ClassName win32_service | where-object name -like "*alg*" | Select-Object -ExpandProperty state

Hope this helps.