Wednesday, February 15, 2012

Needed to quickly check disk space on a bunch of servers today and I found this one-liner via Bartvdw (http://bartvdw.wordpress.com/2008/06/19/powershell-how-to-retrieve-disk-size-free-disk-space-for-a-list-of-computers-input-file/)


Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computer (Get-Content c:\scripts\computers.txt) | Select SystemName,DeviceID,VolumeName,@{Name="size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},@{Name="freespace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}} | Out-GridView

Perfect? No.  But it did the trick and it did it quickly.  And it was a nice reminder to me that if you cut and paste a script from the web, sometimes you need to find and replace all the quotation marks because blog sites like to turn them into pretty quotes instead of the plain straight quote marks that Powershell needs. 

If you get this error:

Unexpected token ':N1' in expression or statement.
At :line:1 char:179
+ Get-WMIObject Win32_LogicalDisk -filter "DriveType=3″ -computer (Get-Content c:\scripts\computers.txt) | Select SystemName,DeviceID,VolumeName,@{Name="size(GB)";Expression={"{0:N1} <<<< " -f($_.size/1gb)}},@{Name="freespace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}} | Out-GridView

Then check your quotes.

No comments:

Post a Comment