Disk Usage Percentage

Power-shell Script to show Disk Usage Percentage.

Disk Usage in Percentage  – A Script to show the usage of system disk in graphical charts. you can copy this script to use in your system Similar kind of script uploaded earlier, the main difference for this script is it will show the disk usage percentage wise so we could identify how much the space is occupied in terms of percent.

This script will load Assemblies and windows form provided by .Net Framework.

How to Use.
Copy below script text to a file called “DiskUsage.ps1″
Run Powershell go to the path where file is saved.
Run script DiskUsage.ps1 for local system
Run script DiskUsage.ps1 x.x.x.x for remote system

Requirement: Powershell v2.0 or later, .Net Framework 4.0 or later

# load the appropriate assemblies
$Form = New-Object Windows.Forms.Form
$Form.Text = “PowerShell Chart”
$Form.Width = 600
$Form.Height = 600
$Label1 = New-Object System.Windows.Forms.Label
$Label1.Font = New-Object System.Drawing.Font(“Cooper Black”, 14.0, [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Point, ([System.Byte](0)))
$Label1.Location = New-Object System.Drawing.Point(40, 5)
$Label1.Size = New-Object System.Drawing.Size(350, 50)
$Label1.TabIndex = 1
$Label1.Text = “Disk Usage in Percentage”
$Label1.BackColor = [System.Drawing.Color]::Transparent
$Label1.ForeColor = [System.Drawing.Color]::DarkRed
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart
$Chart.Width = 500
$Chart.Height = 500
$Chart.Left = 40
$Chart.Top = 30
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
$chartarea.AxisY.Interval = 5
$chartarea.AxisY.Maximum = 100
[void] $Chart.Series.Add(“Data”)
if (!$args)
$Usage_in_Percentage = gwmi win32_logicaldisk -Filter “drivetype=3″ | select deviceid,@{n=’Usage’; e={{0:n2} -f ((($_.size/1gb) – ($_.freespace/1gb)) * 100)/($_.size/1gb) }}
$t = $Usage_in_Percentage | ForEach-Object { $chart.Series[“
Data”].Points.AddXY($_.deviceid,$_.usage) }
$Usage_in_Percentage = gwmi win32_logicaldisk -ComputerName $args -Filter “drivetype=3″
| select deviceid,@{n=’Usage’; e={“{0:n2}” -f ((($_.size/1gb) ($_.freespace/1gb)) * 100)/($_.size/1gb) }}
$t = $Usage_in_Percentage | ForEach-Object { $chart.Series[“Data”].Points.AddXY($_.deviceid,$_.usage) }
$Chart.Series[“Data”].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::column
Script Output

Disk Usage in Percentage

Leave a Reply