Display DiskSize

by johnvanleeuwen at 2012-10-01 23:27:30

Hello,

I’m banging my head against the wall on something. I want to get info on my diskdrives. I have the info I like but a little to much. This is the powershell I use.

Get-WmiObject Win32_LogicalDisk -filter "DriveType=3" | Select DeviceID,VolumeName,@{Name="size(GB)";Expression={"{0:N1}" -f($.size/1gb)}},@{Name="freespace(GB)";Expression={"{0:N1}" -f($.freespace/1gb)}}

Works like a charm, but I want this "script" only to show me a couple of drives. I don’t need to see the "System Reserved" drive or attached network drives. Any idea’s on how to get only the info on, for example; C, D and E drive? Is this possible in a oneliner?

Hope you all can help me out!
by surveyor at 2012-10-02 03:44:51
Hi John,
you can go two easy ways for example:

First you can give your filtercriteria directly to the WMI like this:
Get-WmiObject -Class Win32_LogicalDisk -filter "DriveType=3 and DeviceID like '[DEF]:'" |
Select-Object -Property <br> DeviceID,<br> VolumeName,<br> @{Name=&quot;size&#40;GB&#41;&quot;;Expression={&quot;{0:N1}&quot; -f&#40;$_.size/1gb&#41;}},<br> @{Name=&quot;freespace&#40;GB&#41;&quot;;Expression={&quot;{0:N1}&quot; -f&#40;$_.freespace/1gb&#41;}}</code><br><br>And second you can filter after the WMI has given back all the data:<br><code>Get-WmiObject -Class Win32_LogicalDisk -filter &quot;DriveType=3&quot; |<br> Where-Object { $_.DeviceID -like &#39;[DEF]:&#39; } |<br> Select-Object -Property
DeviceID,
VolumeName,
@{Name="size(GB)";Expression={"{0:N1}" -f($.size/1gb)}},
@{Name="freespace(GB)";Expression={"{0:N1}" -f($
.freespace/1gb)}}


[DEF]: stands for D: or E: or F:

I would prefer the first solution because it’s better to only call for data you need than filter it out later.

PS: I have wrapped the line for better reading.
by RichardSiddaway at 2012-10-02 05:11:36
Filter as soon as possible - especially when retrieving data across the network. You could use the -Property parameter of Get-WmiObject to perform your property filtering
by johnvanleeuwen at 2012-10-05 03:25:47
Thanks! This is working! Thanks for the explanation I get it now!