Skip to content

Instantly share code, notes, and snippets.

@WilliamBerryiii
Created August 10, 2015 20:36
Show Gist options
  • Save WilliamBerryiii/122cefaa0c847be1dc1f to your computer and use it in GitHub Desktop.
Save WilliamBerryiii/122cefaa0c847be1dc1f to your computer and use it in GitHub Desktop.
Powershell to check for impacted drives on a machine.
$drivediskSpace = Get-PSDrive |
## Select the Name, Used amount in GB and Free space in GB
Select-Object Name, @{Name="Used";Expression={$_.Used / 1GB}}, @{Name="Free";Expression={$_.Free / 1GB}} |
## just pick mounted single letter drives to exclude registry
Where {$_.Name.Length -eq 1}
$impactedDrives = $drivediskSpace |
## Select drives where there is more than 0 bytes
## and either more than 80% used or 10GB of disk space remaining
Where { (($_.Free + $_.Used) -gt 0) -and (($_.Used/($_.Free + $_.Used) -gt .8) -or ($_.Free -lt 10)) } |
Select-Object Name, Used, Free
## if there are any drives in out list return the drive and disk amounts or exit 0
if($impactedDrives.Count -gt 0) {
write-output ($impactedDrives | format-list -Property Name, Used, Free, @{Name="% Used";Expression={[system.math]::round($_.Used/($_.Free + $_.Used) * 100)}} | Out-String)
return -1
} else {
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment