


$Check = Test-Path -Path “\\$Server\c$” -ErrorAction Silentl圜ontinue $Object | Add-Member -MemberType NoteProperty -Name “Server name” -Value $Server $Array = Get-Credential “domain\$env:username” $Servers = Get-Content “C:\users\$env:username\desktop\servers.txt” You have to add -Credential parameter in Get-WMIObject commands: Please check also article about getting memory utilization report – link. #$Array | Export-Csv -Path "C:\users\$env:username\desktop\results.csv" -NoTypeInformation -Force $Object | Add-Member -MemberType NoteProperty -Name "CPU %" -Value "(null)" $Object | Add-Member -MemberType NoteProperty -Name "Memory %" -Value "(null)" $Object | Add-Member -MemberType NoteProperty -Name "Is online?" -Value "False" # Display resutls for single server in realtime $Object | Add-Member -MemberType NoteProperty -Name "Is online?" -Value $Status Write-Host "Something went wrong" -ForegroundColor Red $Check = Test-Path -Path "\\$Server\c$" -ErrorAction Silentl圜ontinue $Array | Export-Csv -Path "C:\users\$env:username\desktop\results.csv" -NoTypeInformation -Force $Array | Out-GridView -Title "CPU and Memory" Write-Host "Something went wrong ($Server): "$_.Exception.Message $Object | Add-Member -MemberType NoteProperty -Name "Memory %" -Value $RoundMemory $Object | Add-Member -MemberType NoteProperty -Name "CPU %" -Value $Processor $Object | Add-Member -MemberType NoteProperty -Name "Server name" -Value $Server

$Check = $Processor = $ComputerMemory = $RoundMemory = $Object = $null $Servers = Get-Content "C:\users\$env:username\desktop\servers.txt" $Memory = ((($ComputerMemory.TotalVisibleMemorySize - $ComputerMemory.FreePhysicalMemory)*100)/ $ComputerMemory.TotalVisibleMemorySize) $ComputerMemory = Get-WmiObject -ComputerName $Server -Class win32_operatingsystem -ErrorAction Stop $Processor = (Get-WmiObject -ComputerName $Server -Class win32_processor -ErrorAction Stop | Measure-Object -Property LoadPercentage -Average | Select-Object Average).Average Script is based on Get-WmiObject commands: This is why the following script has been created to avoid similar cases in the future and to quickly identify culprit. Unfortunately SCOM server didn’t catch that CPU or Memory sudden spike and I had to scan all of our servers manually to find what is happening. In past I often had this situation when one of the servers was unresponsive due to high performance which was causing service interruption. This is another great example on how to use PowerShell custom objects and add it to array. If you would like to quickly display CPU and Memory utilization in PowerShell console then this script is for you.
