Windows Server storage capacity and usage report using Powershell

Below Scrip generates list of all Drives and mount points configured, thery storage capacity and free space.

  
# Update 2 parameters $ServerList, $myDiskReport
# Enter the list of servers in #ServerList
 
 
$ServerList = "C:\Users\vijred\Desktop\VJ\Servers.txt"
$myDiskReport = "C:\Users\vijred\Desktop\VJ\DiskReport_$logDate.csv"


$DiskReport = ForEach ($Servername in (get-content $ServerList))  
{Get-WmiObject Win32_Volume -ComputerName $Servername -ErrorAction SilentlyContinue -Filter "Drivetype=3 AND SystemVolume=False"
}

$DiskReport |  Select-Object @{Label = "Server Name";Expression = {$_.SystemName}}, @{Label = "Drive Letter";Expression = {$_.Name}}, @{Label = "Total Capacity (GB)";Expression = {"{0:N1}" -f( $_.Capacity / 1gb)}}, @{Label = "Free Space (GB)";Expression = {"{0:N1}" -f( $_.Freespace / 1gb ) }}, @{Label = 'Free Space (%)'; Expression = {"{0:P0}" -f ($_.FreeSpace/$_.Capacity)}} | Export-Csv -path $myDiskReport -NoTypeInformation       
#

Following Script to check the storage on a single server;


$Servername =  "MYSERVER"

Get-WmiObject Win32_Volume -ComputerName $Servername -ErrorAction SilentlyContinue -Filter "Drivetype=3 AND SystemVolume=False"  |  Select-Object @{Label = "Server Name";Expression = {$_.SystemName}}, @{Label = "Drive Letter";Expression = {$_.Name}}, @{Label = "Total Capacity (GB)";Expression = {"{0:N1}" -f( $_.Capacity / 1gb)}}, @{Label = "Free Space (GB)";Expression = {"{0:N1}" -f( $_.Freespace / 1gb ) }}, @{Label = 'Free Space (%)'; Expression = {"{0:P0}" -f ($_.FreeSpace/$_.Capacity)}} | Format-Table
#

If you want to calculate the storage to be added to maintain certain % of free space on a drive, following Excel formula can be used.

=(C2*F2-100*D2)/(100-F2)
# C2 is Total Storage
# F2 is Target Free%
# D2 is Free storage

12/26/2016:
I had to analyze the disk growth pattern on a server for a single day. Collected the data with 1 minute pause for 1500 times.

$Servername =  "MyServerName"

for ($i=0; $i -le 1500; $i++)
{
Get-WmiObject Win32_Volume -ComputerName $Servername -ErrorAction SilentlyContinue -Filter "Drivetype=3 AND SystemVolume=False"  |  Select-Object @{Label = "CollectionDate"; Expression = {get-date}}, @{Label = "Server Name";Expression = {$_.SystemName}}, @{Label = "Drive Letter";Expression = {$_.Name}}, @{Label = "Total Capacity (GB)";Expression = {"{0:N1}" -f( $_.Capacity / 1gb)}}, @{Label = "Free Space (GB)";Expression = {"{0:N1}" -f( $_.Freespace / 1gb ) }}, @{Label = 'Free Space (%)'; Expression = {"{0:P0}" -f ($_.FreeSpace/$_.Capacity)}} | Format-Table >> diskfreespacereport.txt
Start-Sleep -s 60
}
#
Advertisements
This entry was posted in Powershell, Productivity, Uncategorized, Windows Server and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s