Bulk Add users to existing In-Place hold in Office 365

Today I was being asked to bulk add users to existing In-Place hold in Office 365. As you might know you can do this either via GUI or PowerSehll. Being an IT Professional, I always recommend to leverage script to ease my day to day tasks. Working on PowerShell script that will be used in a longer run to bulk add users to existing In-Place Hold Mailbox Search.

Bulk Add users to existing In-Place hold in Office 365

  • First step is to connect with Exchange Online using PowerShell.
$UserCredential= Get-Credential
$Session= New-PSSession-ConfigurationNameMicrosoft.Exchange-ConnectionUrihttps://outlook.office365.com/powershell-liveid/-Credential$UserCredential-AuthenticationBasic-AllowRedirection
Import-PSSession$Session
  • Once you are connected with Exchange online powershell, Run the following script to bulk add the users to existing In-Place hold.
#Get list of current mailboxes in our mailbox search
$InPlaceHoldMailboxes= (Get-MailboxSearch"InPlaceHold").sourceMailboxes
#Add users to the list of mailboxes to be added in In-Place hold
$InPlaceHoldMailboxes+= "user identifier"
#Add them to the MailboxSearch with InPlaceHoldEnabled
Set-MailboxSearch"InPlaceHold"-SourceMailboxes$InPlaceHoldMailboxes-InPlaceHoldEnabled$true
Once the mailboxes are added to the existing In-Place hold, run the following powershell cmdlet to close the PowerShell session.
Get-PSSession | Remove-PSSession