locked
Cmdlet or Script to alert on mailbox database moved RRS feed

  • Question

  • we have a requirement to fire email alerts whenever a user's mailbox is moved in exchange environment from one database to another or from one server to another however we do not user admin audit logs due to predefined company's policy. Anyone who could provide a script or a code to alert on event wherein user's mailbox is moved. Please suggest. 

    Aditya Mediratta

    Tuesday, January 6, 2015 6:50 AM

Answers

  • Hello Adithya,

    I think it is possible using CmdletExtensionAgent. Below is sample code snippet i can think of.

    <?xml version="1.0" encoding="utf-8" ?>
    <Configuration version="1.0">    
            <Feature Name="Notify Mailbox Move" cmdlets="New-MoveRequest">
             <ApiCall Name="OnComplete">
                 if($succeeded) 
    			 {
                    $MailboxAlias = $provisioningHandler.UserSpecifiedParameters["Alias"]
    				$DisplayName = $provisioningHandler.UserSpecifiedParameters["DisplayName"]
    				$AdminEmailAddress = "Administrator@domain.com"
    				$emailMsg = "Mailbox -" + $MailboxAlias + "With DisplayName -" + $DisplayName + "has been Moved"
    				$EmailSubject = "Mailbox - " + $MailboxAlias +" Has been Moved"
    				Send-MailMessage -From "MailboxMoveNotifyAgent@domain.com" -To $AdminEmailAddress -SMTPserver "smtp.domain.com" -Subject $EmailSubject -Body $emailMsg -BodyAsHTML
    			 }
            </ApiCall>
            </Feature>
    </Configuration>

    Make sure to test it in lab environment before implementing it in production. You may also need to do necessary modifications to this script in case if any error messages is generated.

    For more information about CmdletExtensionAgents you may also refer to:

    http://technet.microsoft.com/en-us/library/dd335054(v=exchg.141).aspx

    http://technet.microsoft.com/en-us/library/dd335067(v=exchg.141).aspx

    http://technet.microsoft.com/en-us/library/dd298143(v=exchg.150).aspx


    Pavan Maganti ~ ( Exchange | 2003/2007/2010/E15(2013)) ~~ Please remember to click “Vote As Helpful&quot; if it really helps and &quot;Mark as Answer” if it answers your question, “Unmark as Answer” if a marked post does not actually answer your question. ~~ This Information is provided is &quot;AS IS&quot; and confers NO Rights!!

    • Proposed as answer by PK M Tuesday, January 6, 2015 3:14 PM
    • Marked as answer by Niko.Cheng Monday, January 19, 2015 1:59 AM
    Tuesday, January 6, 2015 2:58 PM

All replies

  • Hi ,

    Based on my knowledge i have given you some points please have a look in to it.

    Exchange aduit logs are the only hope and that also can be centrally managed by using the EMS as well as via EAC.

    Note : Exchange mailbox replication service is the resposible for the mailbox moves.

    your second option would be to rely on any kind of centralised management tool for collecting the event logs for mailbox moves or else you need to configure the email alert in each and every mailbox severs .

    Step 1: Just move anyone of the maibox from one database to another databse and check is there any events generated on the event viewer of the exchange sever for the mailbox move and that would be related to success or failure move.

    step 2: If none of the events was generated for the mailbox move , we could set the diagonoistic logging level for the mailbox replication service to high to get the in depth events.

    Step 3 : In case if you get the events , then you could configure an email alert to have that event on your mailbox.Email alert Configuration needs to be done on all the mailbox servers or esle it can be done on the centralized tool which is used for event log management.

    But on that tool , you need to configure and collect the events from all the mailbox servers.

    Note : On my side also i don't know which event id will be generated for an succes or failure mailbox move.But you can try it on your side.


    Thanks & Regards S.Nithyanandham

    Tuesday, January 6, 2015 11:53 AM
  • Hello Adithya,

    I think it is possible using CmdletExtensionAgent. Below is sample code snippet i can think of.

    <?xml version="1.0" encoding="utf-8" ?>
    <Configuration version="1.0">    
            <Feature Name="Notify Mailbox Move" cmdlets="New-MoveRequest">
             <ApiCall Name="OnComplete">
                 if($succeeded) 
    			 {
                    $MailboxAlias = $provisioningHandler.UserSpecifiedParameters["Alias"]
    				$DisplayName = $provisioningHandler.UserSpecifiedParameters["DisplayName"]
    				$AdminEmailAddress = "Administrator@domain.com"
    				$emailMsg = "Mailbox -" + $MailboxAlias + "With DisplayName -" + $DisplayName + "has been Moved"
    				$EmailSubject = "Mailbox - " + $MailboxAlias +" Has been Moved"
    				Send-MailMessage -From "MailboxMoveNotifyAgent@domain.com" -To $AdminEmailAddress -SMTPserver "smtp.domain.com" -Subject $EmailSubject -Body $emailMsg -BodyAsHTML
    			 }
            </ApiCall>
            </Feature>
    </Configuration>

    Make sure to test it in lab environment before implementing it in production. You may also need to do necessary modifications to this script in case if any error messages is generated.

    For more information about CmdletExtensionAgents you may also refer to:

    http://technet.microsoft.com/en-us/library/dd335054(v=exchg.141).aspx

    http://technet.microsoft.com/en-us/library/dd335067(v=exchg.141).aspx

    http://technet.microsoft.com/en-us/library/dd298143(v=exchg.150).aspx


    Pavan Maganti ~ ( Exchange | 2003/2007/2010/E15(2013)) ~~ Please remember to click “Vote As Helpful&quot; if it really helps and &quot;Mark as Answer” if it answers your question, “Unmark as Answer” if a marked post does not actually answer your question. ~~ This Information is provided is &quot;AS IS&quot; and confers NO Rights!!

    • Proposed as answer by PK M Tuesday, January 6, 2015 3:14 PM
    • Marked as answer by Niko.Cheng Monday, January 19, 2015 1:59 AM
    Tuesday, January 6, 2015 2:58 PM
  • Hi Pavan,

    I need some more insight on using the above XML code, how do i place a alert for say all the mailboxes hosted on a particular server A_SRV on database name say A_DB ?


    Aditya Mediratta

    Saturday, January 17, 2015 8:10 AM