sdrockzz sdrockzz - 1 year ago 80
Bash Question

power shell script to get drive space ( percentage used and free )

I am trying to get DISK SPACE (Windows) in Percentage used and free.

Script from which I get the space,

get-psdrive | where Free*

Answer Source

You can try this:

Get-WmiObject -Class win32_Logicaldisk -ComputerName localhost |  
where {($_.DriveType -eq 3 -or $_.DriveType -eq 2) -and $_.FileSystem -ne $null } |  
Select -Property 
@{Name = 'Volume';Expression = {$_.DeviceID -replace ":",""}}, 
@{Name = 'Free';Expression = { "{0:N0}%" -f (($_.FreeSpace/$_.Size) * 100) } }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download