PowerGUI – Using Powershell to get Disk Space

This is a script you can use in PowerGUI as a script node. This handy little script will give you the basic information of your drives so you can figure out if you disks are going to run out of space! I had to make a modification to this script, it works much better now! I apologize to everyone who was using the older script, which works well in Powershell but not PowerGUI.

Note: This will work with your existing credentials.

[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null
$name = [Microsoft.VisualBasic.Interaction]::Inputbox(“Enter the IP or Name of the server:”)

$drives = gwmi win32_logicaldisk -ComputerName $name | where{ $_.drivetype -eq 3 }
$driveArray = @()
$counter = 0
foreach ($drive in $drives){
$driveArray += New-Object -TypeName System.Object
$driveArray[$counter] | Add-Member -MemberType NoteProperty -Name name -Value $drive.Name
$driveArray[$counter] | Add-Member -MemberType NoteProperty -Name percentfree -Value ([int] [System.Math]::Round(($drive.FreeSpace) / $drive.Size * 100))
$driveArray[$counter] | Add-Member -MemberType NoteProperty -Name sizeGB -Value ([int]($drive.Size / 1Gb))
$driveArray[$counter] | Add-Member -MemberType NoteProperty -Name freespaceGB -Value ([int]($drive.FreeSpace / 1Gb))
$counter +=1
}
$driveArray | Format-Table

A slimmed down version for the Powershell console can be found here: Console Script

I also made a system monitoring script, free for you to use.

If you found this useful, subscribe to my blog.

Advertisements

One thought on “PowerGUI – Using Powershell to get Disk Space

Have an opinion? Leave an opinion!

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s