I was asked today to make a script that will be used in a bigger one that add’s users into the In-Place Hold Mailbox Search, this Mailbox Search is configured to hold all the deleted emails forever :O

So first if you want to create a Mailbox Search use the following command:

New-MailboxSearch "InPlaceHold"

You better be connected to Office365, if you don’t remember the command:

$UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection Import-PSSession $Session

Now let’s add a mailbox to our Mailbox Search

#Get current mailboxes in our mailbox search $InPlaceHoldMailboxes = (Get-MailboxSearch "InPlaceHold").sourceMailboxes #Add another user to the array, the line bellow can be a loop of more than one user. $InPlaceHoldMailboxes += "user identifier" #Add them to the MailboxSearch with InPlaceHoldEnabled Set-MailboxSearch "InPlaceHold" -SourceMailboxes $InPlaceHoldMailboxes -InPlaceHoldEnabled $true

One last thing to do is to close our session:

Remove-PSSession $Session

Share this: Twitter

Facebook

Like this: Like Loading... Related

Tagged: New-MailboxSearch, Set-MailboxSearch