Error: “You cannot migrate mailbox off of Office365 while the mailbox has a connected account enabled.”

Scenario:  When offboarding a mailbox, you receive the following error:

“You cannot migrate mailbox  off of Office365 while the mailbox has a connected account enabled.”

Solution: You will have to remove the subscription before offboarding the mailbox.

First,  check the subscription to make sure its not anything that’s going to affect the user:

get-subscription –mailbox stevem| FL IncomingServer, SubscriptionType, *Status*, LastSuccessfulSync,IncomingUserName

If it all looks good, run the following to remove the subscriptions:

get-subscription -mailbox stevem | Remove-subscription

 

Determine who has a mailbox and remote mailbox via AD Powershell

Scenario:  You have a list of username’s in a .csv file with a column header labeled: name.  You want to quickly determine which usernames have a Mailbox and RemoteMailbox.

Script:

Import-module ActiveDirectory

$Members = Import-csv C:sharecvusers.csv | Select -ExpandProperty Name

$Members = $Members | Sort

$Members_OnPrem = @()
$Members_o365 = @()

$Members  | %{
    "$_"
    $type = Get-ADUser $_ -properties msExchRecipientTypeDetails | Select -ExpandProperty MSexchRecipientTypeDetails
         If ($type -eq "1"){$Members_OnPrem += $_}
         If ($type -eq "2147483648"){$Members_o365 += $_}
}


Performing a Search-Mailbox with complex search criteria

Scenario: Batman is at it again.  He is now under litigation hold for attacking Superman and you want to search in Superman’s mailbox for any message that was received and sent by Batman, or specific terms were in the Subject, Body, or attachments.  You are only interested for messages sent after 1/1/2012.

Script:

Search-Mailbox Superman -SearchDumpster -SearchQuery "(Received:1/1/2012..5/18/2016) AND (To:Batman@DC.com OR From:Batman@DC.com OR CC:Batman@DC.com OR BCC:Batman@DC.com OR 'Batman' OR 'Bruce' OR 'Wayne')" –targetmailbox BobTheLawyer -loglevel full -targetfolder "Search_Batman"