Wednesday, June 4, 2008

Exchange Power Shell - EMS:

This article explains the features of the exchange management shell EMS. Unlike the previous version of the exchange, the exchange server 2007 has this new feature of accomplishing all the exchange related activity in the command shell. The PowerShell uses the cmdlets as a core technology. A cmdlet is a lightweight command that is used in the PowerShell and Exchange Management Shell environments. Within that environment, the PowerShell command interpreter (PS.exe) executes these cmdlets within the context of automation scripts. The .NET framework is the core package which executes the PowerShell. Nearly 350 exchange related cmdlets are available in the EMS. The EMS works in the back end of the exchange management console.

Uses of EMS:

1. EMS main usage is to perform the administrative functions such as Mailbox management, setting limits for users, Moving mailbox b/w servers, configuring the exchange related parameters, etc.
2. EMS also helps in generating the reports such as recipient details, messaging routing traffic, message size distributions, etc.

General Syntax of the PowerShell Commands:

#Verb-Noun format. The PowerShell commands are auto-tab complete.
Eg., Move-Mailbox, Get-Mailbox, etc.
The commands in the PowerShell can be chained using the pipe option.

Interpreting the PowerShell Commands:

In order to move the mailbox to other server,
In General, Move the Mailbox of the user Stephen to the Mailbox Store2. This can be put syntactically
#Move-Mailbox “Mcgrorty, Stephen” –Targetdatabase “Mailbox Store 2”

Help Option in the EMS:

1. #Get-Help command
2. #Get-Help Set-Mailbox –Parameter *quota*
3. #Get-Help -Role *Mailbox*
Eg, Get-mailboxpermission,Get-mailboxdatabase,etc.
4. #Get-Help -Role *Mailbox* | fl name, synopsis
5. #Get-Help -Component *Recipient*
Eg, Get-mailbox,get-mailboxstatistics,etc.
6. #Get-Help -Functionality *Server*
Eg, Get-mailboxserver,Get-sendconnector,etc.

Pipeline Option:

To move all mailbox in the server1 to the server2
#Get-Mailbox –server server1 | Move-Mailbox –targetdatabase “server2\Mailbox Store1”

To set the maximum send size attribute for the recipient “Andreo Nel”
#Get-Mailbox | where-object { $_.name –like “And*” } | Set-Mailbox –MaxSendSize 10mb

WhatIf and Confirm Option:

To move the mailbox with the name “sandy” to the server2. The –WhatIf parameter informs the administrator what action the script would take and the –Confirm parameter prompts for confirmation before taking action.

#Get-Mailbox | where-object { $_.name –like “sandy*” } | Move-Mailbox –targetdatabase “Server2\Mailbox Store1” –WhatIf

Sample Output:

What if: Performing operation “move-Mailbox” on Target “Move mailbox for:Administrator (Administrator@companyabc.com) to Database: Mailbox Database 2,09014bc6-f977-4961-b4eb-8829fb13e5d6. The operation can take a long time and the mailbox will be inaccessible until the move is complete”.

#Get-Mailbox | where-object { $_.name –like “sandy*” } | Move-Mailbox –targetdatabase “Server2\Mailbox Store1” –Confirm

Sample Output:

Are you sure you want to perform this action? Performing operation “move-Mailbox” on Target “Move mailbox for: Administrator (Administrator@companyabc.com) to Database: Mailbox Database 1,09014bc6-f977-4961-b4eb-8829fb13e5d6. The operation can take a long time and the mailbox will be inaccessible until the move is complete”. [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”):

Some Important and Useful PowerShell Commands In exchange server 2007:

1. To create a new mail database in the first storage group on server2.
#New-MailboxDatabase –StorageGroup “SERVER2\First Storage Group” –name “Mailbox Store2”

2. To mount the above database,
#Mount-database “SERVER2\First Storage Group\Mailbox Store2”

3. To test the connectivity of the recipient mailbox and also to check the latency.
#Test-MapiConnectivity testuser@company.com

4. To get the list of mailbox with the maximum mailbox size,
#Get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2 -ComputerName SERVER1 | select-object MailboxDisplayName,TotalItems,Size | sort -descending “Size” | select-object -first 25

5. The above can also be viewed in the HTML format and also can be directed to some file. This makes it portable.
#Get-wmiobject -class Exchange_Mailbox -Namespace ROOT\MicrosoftExchangev2 -ComputerName SERVER1 | select-object MailboxDisplayName,TotalItems,Size | sort -descending “Size” | select-object -first 25 | ConvertTo-html -title “Top 25 Largest Mailboxes on SERVER1” > “D:\Stats\25 Largest Mailboxes.html”

6. To get the events in the application log with the source starting with the word “Exchange” ,
#get-eventlog Application | where {$_.Source -ilike “Exchange*”} | export-csv c:\events.csv

7. To get the information of particular user mailbox
# Get-Mailbox –Identity "Rudi Kutz"
#Get-Mailbox "Rudi Kutz"
#Get-Mailbox rudi.kutz@philips.com

8. To get the list of exchange servers in the organization,
#Get-ExchangeServer
#Get-ExchangeServer -Domain loguinfo.com
#Get-ExchangeServer –Status

9. To get the mailbox database details,
# Get-MailboxDatabase -Server Server
#Get-MailboxDatabase -StorageGroup StorageGroup

10. To set the quota limit parameter for particular database,
# Set-MailboxDatabase -Identity MailboxDatabase -IssueWarningQuota 500MB

11. To set the user’s mailbox properties like external Email Email address value,
# Set-MailUser -Identity user2 -ExternalEmailAddress test@external.com

12. To get all the records which matching the namespace “logu”, it check in all the possible recipients like user mailbox, contacts, etc.
# Get-Recipient -Anr "logu"

13. To Enable/Disable the user,
# Disable-MailUser -Identity user2
# Enable-Mailbox -Identity company\user1 -Database MailboxDatabase

14. To get the mailbox statistics of the database,
# Get-MailboxStatistics -Database MailboxDatabase
#Get-MailboxStatistics -Server Server

15. To give full access permission for the user1 on the mailbox user2,
#Add-MailboxPermission user2 -User user1 -AccessRights FullAccess

16. The same case if it is a linked mailbox (external mail account which has mailbox in this server),
#Add-MailboxPermission user2 -user CODE1\user1 -AccessRights:FullAccess,ExternalAccount

Likewise there are large number of useful commands in the EMS. Hope the above is informative.

Thanks
Logu
logu_microsoft@hotmail.com
91-98414 99143