Last active
May 29, 2017 23:46
-
-
Save tadcrazio/282d4d6c91540e138bda02f51e8344d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wmidiskblock = { | |
Param($server = "LocalHost", $credential) | |
$Space = Get-WMIObject Win32_LogicalDisk -ComputerName $Server -filter "DriveType=3" -Credential $Credential| Select name, freespace | |
$Ram = Get-WMIObject Win32_OperatingSystem -ComputerName $Server -Credential $Credential | |
$Ram = $Ram.FreePhysicalMemory / 1024 / 1024 | |
$cpu = Get-WmiObject win32_processor -ComputerName $Server -Credential $Credential | Measure-Object -property LoadPercentage -Average | Select Average | |
$serverInfoObject = [PSCustomObject]@{ | |
Name = $Server | |
Disks = $space | |
mem = $Ram | |
cpu = $cpu | |
} | |
Write-host $serverInfoObject.Name | |
if ($serverInfoObject.mem -lt 3) | |
{ | |
$forground = "red" | |
} | |
else | |
{ | |
$forground = "white" | |
} | |
if (($serverInfoObject.cpu.average -as [int]) -gt 85) | |
{ | |
$forground1 = "RED" | |
} | |
else | |
{ | |
$forground1 = "white" | |
} | |
write-host ("mem: " + "{0:F2}" -f $serverInfoObject.mem) -ForegroundColor $forground | |
write-host ("CPU: " + "{0:F2}" -f $serverInfoObject.cpu.Average) -ForegroundColor $forground1 | |
foreach ($disk in $serverInfoObject.Disks) | |
{ | |
$freespaceInGB = [math]::Truncate($disk.freespace / 1gb) | |
if ($freespaceInGB -lt 5 ) | |
{ | |
Write-Host $disk.name " : " $freespaceInGB -ForegroundColor Red | |
} | |
else | |
{ | |
Write-Host $disk.name " : " $freespaceInGB -ForegroundColor white | |
} | |
} | |
} | |
#Start all jobs | |
ForEach ($Server in $ServerList) | |
{ | |
Start-Job -scriptblock $wmidiskblock -ArgumentList $Server, $credential |Out-Null | |
} | |
$out = Get-Job |wait-job -force |Receive-Job | |
$out | export-csv C:\things.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment