Ever needed to check a computer or server and see how much disk space is being used? It could be for multiple reasons such as are any disks too low on space, too much available space assigned(think VMs where you need storage for a new server, but assume all of your storage is tied up), or you just need to see drives that have more than a certain amount of free space due to company standards.
This little one-liner is a great template for you then. This one liner will show any drive on the current computer that has more than 30gb of space free. You could easily change the “-gt” to “-lt” and only show drives with less than 30gb of space free.
Get-PSDrive -PSProvider 'FileSystem' | Where-Object { ($_.Free / 1GB) -gt 30 } | Format-Table -AutoSize
I know your thinking, I can easily click on my computer and check hard drive space, but what about if you have 10, 100, or 1000+ devices you have to manage? Do you really want to do all of those clicks? You could even set this up as a scheduled task and have it notify you, send to teams/discord/etc, or even email a Distribution List with a report. That sounds like a lot better idea than wasting time clicking around.
If your curious on how to have this capture multiple computers, one way is:
$Computers = 'Computer1', 'Computer2', 'Computer3' # Replace with your computer names or IPs
$ScriptBlock = {
Get-PSDrive -PSProvider 'FileSystem' |
Where-Object { ($_.Free / 1GB) -gt 30 } |
Format-Table -AutoSize
}
foreach ($Computer in $Computers) {
Invoke-Command -ComputerName $Computer -ScriptBlock $ScriptBlock
}
I hope you found this one-liner useful, and would love to hear how you use it or have used it in the past! And as always if you have any questions, please feel free to reach out and if I can’t help you out, and I can find someone that can.