This rather simple script will take one or more, local or remote, computer(s) as input and return an object with disk volume information. Should be easy enough to understand, but I’ll try to add some get-help stuff to it later.

#Requires -Version 2

[CmdletBinding()]

param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelinebyPropertyName = $true)]
[String[]]$ComputerName = ([System.Net.Dns]::GetHostName()),
[string]$sizeformat = "1GB"
)

BEGIN{}

PROCESS {
foreach ($computer in $ComputerName){

try {$wmi = Get-WmiObject -ComputerName $computer -ErrorAction Stop -Query "SELECT Systemname,Name,Driveletter,Label,Capacity,Freespace FROM Win32_Volume WHERE DriveType=3"|Select-Object Systemname,Name,Driveletter,Label,Capacity,Freespace}catch{}
$volumeObject = @()
foreach ($volume in $wmi){
if ($wmi){
$capacity = [System.Convert]::ToDecimal((($volume.capacity)/$sizeFormat).ToString("#.00"))
$freespace = [System.Convert]::ToDecimal((($volume.freespace)/$sizeFormat).ToString("#.00"))
$percentfree = [System.Convert]::ToDecimal((($volume.freespace/$volume.capacity)*100).ToString("#.00"))
}

$obj = New-Object -TypeName PSObject
$obj | Add-Member -MemberType NoteProperty -Name Input -Value $computer -PassThru |
Add-Member -MemberType NoteProperty -Name SystemName -Value $volume.Systemname -PassThru |
Add-Member -MemberType NoteProperty -Name Name -Value $volume.Name -PassThru |
Add-Member -MemberType NoteProperty -Name Driveletter -Value $volume.Driveletter -PassThru |
Add-Member -MemberType NoteProperty -Name Label -Value $volume.Label -PassThru |
Add-Member -MemberType NoteProperty -Name Capacity -Value $capacity -PassThru |
Add-Member -MemberType NoteProperty -Name Freespace -Value $freespace -PassThru |
Add-Member -MemberType NoteProperty -Name PercentFree -Value $percentfree

$volumeObject += $obj}

Write-Output $volumeObject}}

END{}

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 )

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