Skip to content

Instantly share code, notes, and snippets.

@tadcrazio
Last active May 29, 2017 23:46
Show Gist options
  • Save tadcrazio/282d4d6c91540e138bda02f51e8344d3 to your computer and use it in GitHub Desktop.
Save tadcrazio/282d4d6c91540e138bda02f51e8344d3 to your computer and use it in GitHub Desktop.
$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