Last active
August 29, 2015 14:25
-
-
Save bryanvine/00476bc57f30ed2c2e2b to your computer and use it in GitHub Desktop.
BV-Get_RemoteHDDInfo_WMI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Version 2.0 | |
Function Get-ServerHDDinfo{ | |
<# | |
.SYNOPSIS | |
Gets all harddrive size info using WMI | |
.DESCRIPTION | |
Returns one object per drive: drive mount, label, total size, used size, used percent, free size. | |
WMI is slower than invoke-command so this is a fail back function for when PSRemoting isn't enabled. | |
.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{ | |
Get-WmiObject -ThrottleLimit 500 -computer $AllServers win32_volume -ErrorAction SilentlyContinue | | |
?{$_.drivetype -eq 3 -and $_.Capacity -gt 0} | %{ | |
$obj = New-Object PSobject | |
$obj | Add-Member NoteProperty Name $_.PSComputerName | |
$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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment