Posted On December 19, 2020

PowerShell: Quick Script to Get Storage Utilization

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Quick Script to Get Storage Utilization
$volumes = (gwmi -Class win32_volume -Filter "DriveType!=5" -ea stop| ?{$_.DriveLetter -ne $isnull}|`
        Select-object @{Name="Letter";Expression={$_.DriveLetter}},`
        @{Name="Label";Expression={$_.Label}},`
        @{Name="Capacity";Expression={"{0:N2} GiB" -f ($_.Capacity/1073741824)}},`
        @{Name = "Available"; Expression = {"{0:N2} GiB" -f ($_.FreeSpace/1073741824)}},`
        @{Name = "Utilization"; Expression = {"{0:N2} %" -f  ((($_.Capacity-$_.FreeSpace) / $_.Capacity)*100)}}`
        | sort -property Letter |ft -autosize | Out-String).Trim()
write-host "Current storage stats:`r`n$volumes"
Sample Output:

Current storage stats:
Letter Label  Capacity  Available Utilization
------ -----  --------  --------- -----------
C:     System 79.90 GiB 11.99 GiB 85.00 %
D:     Data   49.87 GiB 41.16 GiB 17.48 %
P:     Page   32.00 GiB 15.38 GiB 51.93 %

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Process Watcher

# processWatcher.ps1 # User Input $serviceName='MSCRMAsyncService$maintenance' # Semi-autogen variables $desiredStatus='Running' $environment=($env:computername).substring(0,$env:computername.IndexOf('-')) $reportServer="$environment-SQL01" function checkService($computername=$env:computername,$serviceName,$status='Running'){ #…

PowerShell: Running Commands on Remote Computers

# runCommandsOnRemoteComputers.ps1 # User defined variables $computernames=@( 'SERVER001', 'SERVER002' ) $expectedExecutable='racadm.exe' $expectedInstallPath='C:\program files\Dell\SysMgt\iDRACTools\racadm' # Execution…

PowerShell: Create Daily VSS Snapshot of Volumes on Local Windows Machine

<# Daily-VSS-Snapshot-Windows-Standalone-FileServer.ps1 Functions: 1. Dynamically detect all volumes on local machine 2. Take snapshots of…