Forum Discussion
Automatically put mailbox on lithold
- Dec 08, 2021As Vasil recommended, if users are in Exchange Online you can use Retention Policies in security and compliance center to ensure mailbox data is not deleted.
If you want to use PowerShell to find users with a specific license and then enable litigation hold you can try the following command:
$Users = Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match "Contoso:EnterprisePack"}
$Users | %{Set-Mailbox $Users.UserPrincipalName -LitigationHoldEnabled $true}
Note: match phrase "Contoso:EnterprisePack" is the account SKU (License) that you are looking for, you can find the SKU using the following command: Get-MsolAccountSku and replace it accordingly
If you want to use PowerShell to find users with a specific license and then enable litigation hold you can try the following command:
$Users = Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match "Contoso:EnterprisePack"}
$Users | %{Set-Mailbox $Users.UserPrincipalName -LitigationHoldEnabled $true}
Note: match phrase "Contoso:EnterprisePack" is the account SKU (License) that you are looking for, you can find the SKU using the following command: Get-MsolAccountSku and replace it accordingly
- Skipster311-1Dec 08, 2021Iron Contributor
Thanks. I want to do a check to see if the mailbox is currently on lithold first. This is what i put together
$pimserviceaccount = "admin.@mycompany.onmicrosoft.com"
$adminpassword = "01000000d08c9ddf0115d1118c7a00c04fc297eb0100000084b78e199e1c3b478efd799c7aab6a910000000002000000000003660000c0000000100000000d19998b9fdab9ec1f44820c65de76fd0000000004800000a000000010000000dce05d1d250d5882967e46b97ecbd0c218000000ab0ceed45aa0a431a0137017b3479b6a6ea8e9694b41327714000000d1b19a01c628ceffedd753a5e2b53d0cd90fb930"
$secureString = ConvertTo-SecureString -String $adminpassword
$cred = New-Object -TypeName PSCredential -ArgumentList $pimserviceaccount, $secureString
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking
$Lithold = Get-MsolUser -all:$true | Where-Object {($_.licenses).AccountSkuId -match "SPE_E5" -or ($_.licenses).AccountSkuId -match "EXCHANGEARCHIVE_ADDON" -or ($_.licenses).AccountSkuId -match "SPE_F1" -or ($_.licenses).AccountSkuId -match "SPE_F5_SECCOMP"} |select UserPrincipalname
$lithold |ForEach-Object {Get-Mailbox -Identity $_.userprincipalname} | Where-Object {$_.litigationholdenabled -eq $false} |set-mailbox -LitigationHoldEnabled:$true