Tuesday, April 7, 2015

power shell script to check cpu,disk space,memory usage for bulk servers

Instructions :


Create a text file that contains list of servers in c:\servers.txt ( You can create in some other location also )


Output --> C:\new\report.csv

You will not get the output If you don't have write or read access on the drive


#########################################

GC C:\Servers.txt | % {
$Comp = $_
If (Test-Connection $Comp -Quiet){
$Mem = GWMI -Class win32_operatingsystem -computername $COMP
New-Object PSObject -Property @{
Server = $Comp
"CPU usage" = "$((GWMI -ComputerName $COMP win32_processor | Measure-Object -property LoadPercentage -Average).Average) %"
"Memory usage" = "$("{0:N2}" -f ((($Mem.TotalVisibleMemorySize - $Mem.FreePhysicalMemory)*100)/ $Mem.TotalVisibleMemorySize)) %"
"Total FreeSpace" = "$("{0:N2}" -f ((Get-WmiObject -Class win32_Volume -ComputerName $COMP -Filter "DriveType = '3'" | Measure-Object -property FreeSpace -Sum).Sum /1GB)) GB"
}
 }
 Else{
 "" | Select @{N="Server";E={$Comp}},"CPU usage","Memory usage","Total FreeSpace"
 }
}| Select Server,"CPU usage","Memory usage","Total FreeSpace" |
Export-Csv C:\new\report.csv -nti





Get the script here ------------> Bulk server cpu memory disk space usage

No comments:

Post a Comment