Get-DiskSpace

The Get-DiskSpace cmdlet from the NTFSsecurity module is useful in that it gives ready calculated percentages of free and used space:

AvailableFreeSpacePercent  : 56.73%
AvailableFreeSpaceUnitSize : 270.11 GB
ClusterSize                : 4096
DriveName                  : \\?\Volume{c1c4c5bb-0000-0000-0000-f01500000000}\
TotalSizeUnitSize          : 476.1 GB
UsedSpacePercent           : 43.27%
UsedSpaceUnitSize          : 206 GB
FreeBytesAvailable         : 290024239104
TotalNumberOfBytes         : 511210610688
TotalNumberOfFreeBytes     : 290024239104
BytesPerSector             : 512
NumberOfFreeClusters       : 70806699
SectorsPerCluster          : 8
TotalNumberOfClusters      : 124807278

BUT as you can see it doesn’t identify the Drive Name by user friendly name.

You can do

PS> Get-DiskSpace -DriveLetter C:

AvailableFreeSpacePercent  : 56.73%
AvailableFreeSpaceUnitSize : 270.1 GB
ClusterSize                : 4096
DriveName                  : C:\
TotalSizeUnitSize          : 476.1 GB
UsedSpacePercent           : 43.27%
UsedSpaceUnitSize          : 206 GB
FreeBytesAvailable         : 290020270080
TotalNumberOfBytes         : 511210610688
TotalNumberOfFreeBytes     : 290020270080
BytesPerSector             : 512
NumberOfFreeClusters       : 70805730
SectorsPerCluster          : 8
TotalNumberOfClusters      : 124807278

but that means passing each drive separately. The DriveLetter parameter should take an array of drives according to the syntax diagram but that doesn’t seem to work.

Try running something like

Get-Volume |
where DriveLetter |
sort Driveletter |
foreach {
    Get-DiskSpace -DriveLetter “$($_.Driveletter):” |
    select DriveName, TotalSizeUnitSize, UsedSpaceUnitSize,
    AvailableFreeSpaceUnitSize, UsedSpacePercent, AvailableFreeSpacePercent  
}

and you get a nice output

DriveName                  : C:\
TotalSizeUnitSize          : 476.1 GB
UsedSpaceUnitSize          : 206 GB
AvailableFreeSpaceUnitSize : 270.1 GB
UsedSpacePercent           : 43.27%
AvailableFreeSpacePercent  : 56.73%

Advertisements
This entry was posted in Powershell. Bookmark the permalink.

1 Response to Get-DiskSpace

  1. Luke says:

    Interesting finding! Just wondering why they implemented this cmdlet in the NTFS security module… There is no evident link between NTFS acls and disk space.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s