Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
BV-Get_RemoteHDDInfo_PSRemoting
#Requires -Version 3.0
Function Get-ServerHDDinfo{
<#
.SYNOPSIS
Gets all harddrive size info using Invoke-Command (PS Remoting)
.DESCRIPTION
Returns one object per drive: drive mount, label, total size, used size, used percent, free size.
.PARAMETER ComputerName
One or more server names to pull hdd info from.
.EXAMPLE
Get-ServerHDDinfo -ComputerName (Get-Content .\myserverlist.txt)
Returns an object array of the attached hdds on all servers in the list txt file.
.EXAMPLE
'server1','server2' | Get-ServerHDDinfo | Export-Csv -NoTypeInformation .\Report.csv
Returns an object array of the attached hdds on server's 1 & 2 and outputs it to a CSV file
.LINK
http://www.bryanvine.com/2015/07/powershell-script-get-serverhddinfo.html
.LINK
Get-WmiObject
.NOTES
Author: Bryan Vine
Last updated: 7/22/2015
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,valuefrompipeline=$true,Position=0)]
[alias("CN","MachineName","ServerName","Server")][ValidateNotNullOrEmpty()][string[]]
$ComputerName
)
BEGIN{$AllServers=@()}
PROCESS{$AllServers += $ComputerName}
END{
Invoke-Command -AsJob -ThrottleLimit 100 -ComputerName $AllServers -HideComputerName -ScriptBlock{
Get-WmiObject win32_volume -ErrorAction SilentlyContinue |
?{$_.drivetype -eq 3 -and $_.Capacity -gt 0} | %{
$obj = New-Object PSobject
$obj | Add-Member NoteProperty Name $env:ComputerName
$obj | Add-Member NoteProperty "Mount" $_.Name
$obj | Add-Member NoteProperty "Label" $_.VolumeName
$obj | Add-Member NoteProperty "TotalSize(GB)" ("{0:n3}" -f ($_.Capacity /1gb))
$obj | Add-Member NoteProperty "Used(GB)" ("{0:n3}" -f (($_.Capacity - $_.FreeSpace) /1gb))
$obj | Add-Member NoteProperty "Used(percent)" ("{0:n0}" -f (100 - ($_.FreeSpace /$_.Capacity * 100)))
$obj | Add-Member NoteProperty "Free(GB)" ("{0:n3}" -f ($_.FreeSpace /1gb))
Write-Output $obj
}
} | Receive-Job -AutoRemoveJob -Wait
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment