Exchange Auto check

$Header = "<style>table {font-size: 10pt; font-family: calibri;}

  building {background-color:black;}

  table {align: cernter; border-width: 1px;border-style: solid; border-color: black; border-collapse: collapse;}

  th {font-size:1em; border-width: 1px;padding: 2px; border-style: solid; border-color: white; background-color: #FFCCCC}

  td {font-size:0.8em; border-width: 1px;padding: 2px; border-style: solid; border-color: white; background-color: PaleGoldenRod}

</style>"

$Getdate = Get-date

 

$TotalGB = @{Name="Capacity(GB)";expression={[math]::round(($_.Capacity/ 1073741824),2)}}

$FreeGB = @{Name="FreeSpace(GB)";expression={[math]::round(($_.FreeSpace / 1073741824),2)}}

$FreePerc = @{Name="Free(%)";expression={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}

 

function get-mountpoints {

$volumes = Get-WmiObject -computer $server win32_volume | Where-object {$_.DriveLetter -eq $null}

$volumes | Select SystemName, Label, $TotalGB, $FreeGB, $FreePerc

}

 

$servers = (Get-Content .\servers.txt)

$target = @()

foreach ($server in $servers){

$target += get-mountpoints

$file = $target |Export-csv -NoTypeInformation -Force -Path 'C:\folder\MountPointSpace-Report.csv'

 

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

Get-MailboxDatabase | Get-MailboxDatabaseCopyStatus |select Name,Status,CopyQueueLength,ReplayQueueLength,LastInspectedLogTime| Export-csv "C:\folder\DatabasesIndexStatus.csv"

 

 

Get-Queue -server <server name>|select Identity,DeliveryType,Status,MessageCount,NextHopDOmain| Export-csv "C:\folder\Queue_status_servername1.csv"

 

Get-queue -server <Server name>|select Identity,DeliveryType,Status,MessageCount,NextHopDOmain| Export-csv "C:\folder\Queue_status_Servername2.csv"

 

Get-queue -server <server name>|select Identity,DeliveryType,Status,MessageCount,NextHopDOmain| Export-csv "C:\folder\Queue_status_servername3.csv"

 

 

$ExchangeInfo = Import-Csv -Path C:\folder\MountPointSpace-Report.csv| ConvertTo-Html -Head $Header

$ExchangeInfo2 = Import-Csv -Path C:\folder\DatabasesIndexStatus.csv| ConvertTo-Html -Head $Header

$ExchangeInfo3 = Import-Csv -Path C:\folder\Queue_status_servername1.csv| ConvertTo-Html -Head $Header

$ExchangeInfo4 = Import-Csv -Path C:\folder\Queue_status_servername2.csv| ConvertTo-Html -Head $Header

$ExchangeInfo5 = Import-Csv -Path C:\folder\Queue_status_servername3.csv| ConvertTo-Html -Head $Header

 

$mailBody = 

@"

Hello Messaging Admins,</br>

</br>

<p>Here are the <b>Exchange Auto Check</b> info. Please have a look.</p></br>

</br>

$ExchangeInfo

</br>

$ExchangeInfo2

</br>

$ExchangeInfo3

</br>

$ExchangeInfo4

</br>

$ExchangeInfo5

</br>

 

Best</br>

Gautam Verma

"@

 

Send-MailMessage -building $mailBody -BodyAsHtml `

-From "Gautam.Verma@domain.com" -To "admin@domain.com" `

-Subject "Test Exchange $Getdate"`

-SmtpServer "smtp.domain.com"