Sunday, October 28, 2012

Very Useful Exchange Cmdlets

Some useful EMS Cmdlets to get the valuable information from Exchange Server 2010, as per your Organization requirements:

Number of E-mails Sent and Received by one User

This is very powerful script used to check the Send & Receive Emails by a user:

[Int] $intSent = $intRec = 0
Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -Start “10/01/2012” -End “11/01/2012” -Sender "" -   EventID RECEIVE | ? {$_.Source -eq "STOREDRIVER"} | ForEach { $intSent++ }
Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -Start “10/01/2012” -End “11/01/2012” -Recipients "" -EventID DELIVER | ForEach { $intRec++ }

                                Get Recoverable Items folder size per Database

This script is used to get the size of recoverable items of per Mailbox-Database:

Get-MailboxFolderStatistics nuno –FolderScope RecoverableItems | Select Identity, FolderAndSubfolderSize
[Int] $total = 0
(Get-Mailbox -Database MDB16 -ResultSize Unlimited) | ForEach {$total += (Get-MailboxFolderStatistics $_ -FolderScope RecoverableItems | ? {$_.Identity -match "Recoverable Items"}).FolderAndSubfolderSize.ToMB()}

This script is used to update or modified the IP Address on Exchange Receive Connector:

# Get Receive Connectors to update
$recCons= Get-ReceiveConnector | Where {$_.Name -match"Unauthenticated SMTP"}
ForEach ($recConin$recCons)
      Write-Host"Updating", $recCon.Identity
       $recCon.RemoteIPRanges -=""
      $recCon.RemoteIPRanges -=""
       Set-ReceiveConnector $recCon -RemoteIPRanges$recCon.RemoteIPRanges

This script is used to create a Transport Rule in Exchange Serve 2010:

New-TransportRule “Block Non Delivered e-mails from Nuno” -Comments ”Prevent Nuno from forwarding NDRs e-mails” -From “” -SentToScope “NotInOrganization” -SubjectContainsWords “FW: There was an error sending your mail”, “FW: Mail delivery failed”, “FW: failure notice” -RedirectMessageTo “”-Enabled $True

This script is used to check the full access permissions to any other User-Mailbox:

Get-Mailbox -Resultsize Unlimited | Get-MailboxPermission -User | ? {$_.AccessRights -match "FullAccess" -and$_.IsInherited -eq $False} | Select Identity
ForEach ($mbx in (Get-Mailbox -Resultsize Unlimited | Select Identity)) {Get-MailboxPermission $mbx.Identity -User | ? {$_.AccessRights -match "FullAccess" -and $_.IsInherited -eq $False} | Select Identity}

This script is used to make the comparisons between the Primary & Secondary IP Address:

[String] $strPrimaryAddress
[String] $strSIP
[Array] $arrCollection = @()

ForEach ($mbx in (Get-Mailbox -ResultSize Unlimited))
       # Initialize object to hold all the information
       $mbcomb = "" | Select "Display Name", "Primary SMTP Address", "SIP"
       # Reset variables
       $strPrimaryAddress = $strSIP = $NULL

       # Check all the e-mail aliases the user has
       $mbx.EmailAddresses | ForEach {
              If ($_.IsPrimaryAddress -and $_.Prefix -match "SMTP") { $strPrimaryAddress = $_.SmtpAddress }
              If ($_.PrefixString -eq "sip") { $strSIP = $_.AddressString }
       # Compare the primary SMTP with the SIP address
       If ($strPrimaryAddress -ne $strSIP)
              $mbcomb."Display Name" = $mbx.DisplayName
              $mbcomb."Primary SMTP Address" = $strPrimaryAddress
              $mbcomb."SIP" = $strSIP
              $arrCollection += $mbcomb

# Print or export all the results
$arrCollection | FT
#$arrCollection | Export-Csv D:\Scripts\"SMTPvsSIP_$(Get-Date -f 'yyyyMMdd').csv" -NoType

get-mailbox | where {$_.UseDatabaseQuotaDefaults -ne $true}

Get-Mailbox Database Statics

This command is used for get the Mailbox Database statics:

[PS] C:\>Get-MailboxDatabase 
Name                           Server          Recovery        ReplicationType                                        
----                           ------          --------        ---------------                                        
Mailbox Database 0020849825    Exchangeby-Arun-Ex001  False           Remote                                                 
Mailbox Database 2       Exchangeby-Arun-Ex-02  False           Remote                                                 

If you like these scripts, please leave your comments here.

                              Arun chaudhary
                             Email me:
Post a Comment