Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I know the disk name that have the max freespace? 1

Status
Not open for further replies.

new2ps

IS-IT--Management
Aug 31, 2008
1
IL
would like to know the logical disk name that have the MAX FreeSpace

for example I have drive C: and drive D: and I want to know where i have the most freespace

I run:

get-wmiobject win32_logicaldisk |measure-object -property freespace -max

I get:
Count : 3
Average :
Sum :
Maximum : 3883384832
Minimum :
Property : freespace

BUT - How can I know if it refers to drive C: ? or D: ?

TIA
 
Here's one solution. As I'm still learning PowerShell myself, there's probably a more efficient way to do it. Note that this restricts the retrieval to only "Local Fixed" disks (drivetype 3) in case you have mapped drives to network resources.
Code:
get-wmiobject win32_logicaldisk -filter "drivetype=3" | sort freespace -desc | select -first 1 | format-table caption, description, freespace, size, drivetype
 
Don't care if you are still learning or wrote PowerShell, have a star for telling us how to do it. Nice one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top