Last active
August 29, 2015 14:25
-
-
Save bryanvine/0a32a35c30d414f2c1c3 to your computer and use it in GitHub Desktop.
BV-Get_RemoteHDDInfo_PSRemoting
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 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