Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

SQLTechnet

Vinoth is currently a Senior SQL Server DBA and 10 years of experience as SQL Server DBA. Started my career as a DBA in SQL 6.5/7 has worked in all subsequent SQL Server version. Vinoth has worked in some of the largest SQL server environments in the world in various domains ranging from Finance, Retail, Manufacturing, Consulting, Web etc. Vinoth has Engineering Degree in Computer Science and has certified in MCITP - Database Adminstrator in 2008/2005, MCDBA and ITIL Foundation V3.

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"
}

Comments

Leave a comment on the original post [www.sqltechnet.com, opens in a new window]

Loading comments...