by johnvanleeuwen at 2012-10-01 23:27:30
Hello,by surveyor at 2012-10-02 03:44:51
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!
Hi John,by RichardSiddaway at 2012-10-02 05:11:36
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="size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},<br> @{Name="freespace(GB)";Expression={"{0:N1}" -f($_.freespace/1gb)}}</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 "DriveType=3" |<br> Where-Object { $_.DeviceID -like '[DEF]:' } |<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.
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 filteringby johnvanleeuwen at 2012-10-05 03:25:47
Thanks! This is working! Thanks for the explanation I get it now!