Exchange Server 2013 Disk Space Report


The below script will helps to provide the detail on disk space and mount volume in the Exchange Server. The output of the file will be saved in the desktop and also it will send as email with an attachment

Exchange 2013 Disk Space
# Where to store output
$savefile  = $env:USERPROFILE + ‘\Desktop\’ +((Get-Date).ToString(“dd_MM_yyyy_HHmm”))+’.html’

#Preformat HTML document
$a = “<style>”
$a = $a + “BODY{background-color:peachpuff;}”
$a = $a + “TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}”
$a = $a + “TH{border-width: 1px;text-align: center; margin: 2px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}”
$a = $a + “TD{border-width: 1px;text-align: center; margin: 2px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}”
$a = $a + “</style>”

# Function to for the Output

$Serverslist = get-content(“C:\scripts\server.txt”)

$html =””

$SizeInGB=@{Name=”Size(GB)”; Expression={“{0:N2}” -f ($_.Capacity/1GB)}}
$FreespaceInGB=@{Name=”Freespace(GB)”; Expression={“{0:N2}” -f ($_.Freespace/1GB)}}
$PercentFree=@{Name=”PercentFree(%)”;Expression={[int](($_.Freespace/$_.Capacity)*100)}}
$ServerName = @{Expression={$_.__Server};Label=”Server Name”}

$outputvalues =@()
$serverlist = @()
$notaccessible= @()

Write-output “Gathering Disk Usage Information……..”
foreach ($server in $Serverslist)
{
$outputvalues = gwmi -query “Select  __SERVER,  Name, Capacity, FreeSpace FROM win32_volume where not Name like ‘\\%Volume%’ and drivetype <>5” -Computer $server |
Select-Object $ServerName,  Name, $SizeInGB, $FreespaceInGB, $PercentFree
$serverlist = $serverlist + $outputvalues
}

$Output = $serverlist | ConvertTo-Html -head $a -body “<H2>EXCHANGE 2013 SERVERS DISK SPACE REPORT</H2>”

$Report = $Output |Out-File $savefile

#To Send Email

$MailTo = “Raji.Subramanian@mail.com”
$MailFrom = “Admin@mail.com”
$MailServer = “Exserver.mail.com”

Send-MailMessage -Attachments $savefile -To $MailTo -From $MailFrom -Subject “EXCHANGE 2013 SERVERS DISK SPACE REPORT” -Body ( $Output | out-string ) -bodyashtml –

SmtpServer $MailServer

To add them in the task schedule copy the below command and paste them in the command of new task

#C:\Windows\System32\WindowsPowerShell\v1.0\Powershell.exe -Command “.’E:\Program Files\Microsoft\Exchange Server\V15\Bin\RemoteExchange.ps1′; Connect-ExchangeServer

-auto; C:\Scripts\DiskReport.ps1

Advertisements

About Raji Subramanian

Nothing great to say about me...Just want to share my knowledge for others that will be useful at any moment of time when they stuck in critical issue....
This entry was posted in Exchange 2013 SP1, Exchange Server, Exchange Server 2013 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