Blog Post

Drive Size - PowerShell Script

,

The below script is used to find the disk size for a set of servers,

#
# Script to Find List of drives and Size of Drive in given set of server
# Created by - Vinoth N Manoharan
# Version 1.1
# Date - 15/09/2011
# Script Help :-
#---------------
# Parameter 1 :- "-s" to run powershell for Single server
# "-f" to give filename with list of servers
# Parameter 2 :- Server name(if -s is the parameter 1) or Filename with fully defined path(if -f is the parameter 1)
#
# Example1:- FindDiskSize.ps1 -s <servername>
# Example2:- FindDiskSize.ps1 -f <filename with fully define path like c:\test.txt>
Clear-Host
$List =@()
if($args.Length -ne 2)
{
Write-Host "Incorrect Paramenter Count use either -s or -f to specify the servername/Serverlist"
}
elseif(($args[0] -eq "-s"-or ($args[0] -eq "-S"))
{
$computer = $args[1]
$drives = @()
if($computer -ne $null)
{
$srt = "Server Name :- " + $computer
$srt
Echo "---------------------------"
# Properties for PowerShell logical disk object:
$drives = Get-WmiObject -ComputerName $computer Win32_LogicalDisk | Where-Object {$_.DriveType -eq3}
$drives | Add-Member -MemberType ScriptProperty -Name SizeGB -Value{[math]::Round(($this.Size/1GB),2)} -PassThru |
Add-Member -MemberType ScriptProperty -Name FreeSpaceGB -Value{[math]::Round(($this.FreeSpace/1GB),2)} -PassThru |
ft Name, SizeGB, FreeSpaceGB -AutoSize
}
}
elseif(($args[0] -eq "-f"-or ($args[0] -eq "-F"))
{
$filename = $args[1]
$computers = get-content $filename
foreach ($computer in $computers)
{
$drives = @()
if($computer -ne $null)
{
$srt = "Server Name :- " + $computer
$srt
Echo "---------------------------"
# Properties for PowerShell logical disk object:
$drives = Get-WmiObject -ComputerName $computer Win32_LogicalDisk | Where-Object {$_.DriveType -eq3}
$drives | Add-Member -MemberType ScriptProperty -Name SizeGB -Value{[math]::Round(($this.Size/1GB),2)} -PassThru |
Add-Member -MemberType ScriptProperty -Name FreeSpaceGB -Value{[math]::Round(($this.FreeSpace/1GB),2)} -PassThru |
ft Name, SizeGB, FreeSpaceGB -AutoSize
}
}
}
else
{
Write-Host "Incorrect Paramenter, use either -s or -f to specify the servername/Serverlist"
}

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating