Exchange 2010 PowerShell Tips & Snippets

This is a page of various Exchange 2010 Powershell one liners that I use fairly often or want quick access to.

Load Exchange 2010 snappin at the start of a PowerShell script

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

Adding –whatif to the end of most command lines will go through the motions without making any changes.  This is very useful for debugging and validating commands

Generate a list of Exchange Servers

Get a list of all Exchange servers, version numbers and roles in the organisation:

Get-ExchangeServer

Count the number of mailboxes

Get-Mailbox | Group-Object -Property:ServerName | Select-Object name,count

Permissions Admin

For more a detailed look at mailbox permissions see this post

Grant Full Access to a mailbox

Give John Full Access to Fred’s mailbox:

Add-MailboxPermission "Fred" -user "John" -AccessRights FullAccess

Remove access to a mailbox

Remove John’s access to Fred’s mailbox:

remove-MailboxPermission "Fred" -user "John" -AccessRights FullAccess

Grant Send-as permission to a mailbox

Full Access permissions to a mailbox do not grant the Send As permission which is an AD permission.  To give John the rights to be able to send e-mail from Fred’s mailbox type:

Add-AdPermission "fred" -user "John" -extendedrights "Send As"

Mailbox Admin

List all databases and mailbox count for Exchange 2010 only.

get-mailbox -ResultSize unlimited -Filter {(ExchangeVersion -eq '0.10 (14.0.100.0)')} | Group-Object -Property:Database | Select-Object name,count | ft -AutoSize

* You may need to update the version number depending on your Service Pack and Roll Up level, here is a list http://technet.microsoft.com/library/hh135098.aspx

Database Admin

Failover all databases

To failover all the mailbox databases in a DAG to a particular server use the following:

Move-ActiveMailboxDatabase -server NewActiveServerName -confirm:$false

Losslessly failover a single database called Maiboxes1 to the server called GOODMBX

Move-ActiveMailboxDatabase -Identity 'Mailboxes1' -ActivateOnServer 'GOODMBX' -MountDialOverride 'Lossless'

Redistribute the databases

All databases have a preferred MBX server.  To put databases back to their preference:

cd $exscripts
./RedistributeActiveDatabases.ps1 -BalanceDbsByActivationPreference -confirm:$false

* On a default install $exscripts is set to –  C:\Program Files\Microsoft\Exchange Server\V14\Scripts )

List all mailbox databases with mailbox count

List all databases with a mailbox count for each.  If you have a mixed environment this will include the databases from Exchange 2003 as well.

Get-Mailbox | Group-Object -Property:Database | Select-Object name,count

Detect and repair a mailbox database in the “Failed and Suspended” state

After a mailbox database crash/failure the databases may be in a “failed and suspended” state. To check for this type:

Get-MailboxDatabaseCopyStatus -server MAILBOXSERVER |?{$_.status -like "Failed*"}

Or

Get-MailboxDatabaseCopyStatus -Server MAILBOXSERVER | ?{$_.ContentIndexState -eq "Failed"}

If a failed database is detected it may be necessary to suspend and then reseed the database from the good copy.  This example reseeds a failed database called mailboxes1 on the mailbox server that crashed called FailedMBX .  It uses the good copy from the DAG server called GoodMBX.

Suspend-MailboxDatabaseCopy -Identity "mailboxes1\FailedMBX" Update-MailboxDatabaseCopy -Identity "mailboxes1\FailedMBX" -SourceServer GoodMBX -DeleteExistingFiles resume-MailboxDatabaseCopy -Identity "mailboxes1\FailedMBX"

Mount or Dismount a mailbox database

Mount a database / public folder –

Mount-Database "public folder database"

Dismount a database:

Dismount-Database "public folder database"

Change the log files location

Move logfiles: (http://technet.microsoft.com/en-us/library/bb124742.aspx)

Move-DatabasePath –Identity "Mailboxes1" –LogFolderPath "T:\Mailboxes1"

OWA (Outlook Web App)

To test Autodiscover is working

To check if autodiscover is working browse to this URL, you will need to substitute CASARRAY for your CAS Array name.   If successful you should get a screen of XML.

https://CASARRAY/EWS/Exchange.asmx

* standard disclaimer – use this info at your own risk, test in a development environment and ensure you have a back out plan if it all goes wrong.  I take no responsibility at all for anything posted in this blog site.

Posted on July 16, 2012 at 20:11 by simon · Permalink
In: Exchange 2010 · Tagged with: , , , , , , ,

Leave a Reply