PowerShell Script to get disk size in MB and Used space

Below is PowerShell script to get disks size in MB and Used space in GB:

Get-Wmiobject -query "select name,driveletter,capacity,freespace from win32_volume where drivetype=3" | Format-Table -autosize Name, @{ label="SizeGB"; Expression={($_.capacity / 1GB).tostring("F0")}}, @{ label="UsedSizeGB"; Expression={(($_.capacity/1GB) - ($_.freespace/1GB)).tostring("F0")}},
@{label="FreeGB"; Expression={($_.freespace / 1GB).tostring("F0")}}, @{label="Free%"; Expression={($_.freespace*100/$_.capacity).tostring("F0")}}, @{ label="SizeMB"; Expression={($_.capacity / 1MB).tostring("F0")}} >C:\Temp\DisksSizeinMB.txt


Values explained:
@{label="SizeGB"; Expression={($_.capacity / 1GB).tostring("F0")}},
@{label="UsedSizeGB"; Expression={(($_.capacity/1GB) - ($_.freespace/1GB)).tostring("F0")}},
@{label="FreeGB"; Expression={($_.freespace / 1GB).tostring("F0")}},
@{label="Free%"; Expression={($_.freespace*100/$_.capacity).tostring("F0")}},
@{label="SizeMB"; Expression={($_.capacity / 1MB).tostring("F0")}} 

Comments

Popular posts from this blog

vRA/vRO workflows

How to generate HPS Report for Windows