The following PowerShell script will check for Exchange Online mailboxes not provisioned with an Online Archive and enable archiving.
# Enable archive on all mailboxes
write-host "Connecting to Exchange Online Powershell.."
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -AllowClobber
# Get list of user/shared mailboxes without Archiving enabled
$MissingArchive = Get-Mailbox -Resultsize Unlimited -Filter {ArchiveStatus -ne "Active" -AND (RecipientTypeDetails -eq "UserMailbox" -OR RecipientTypeDetails -eq "SharedMailbox")}
# Enable archive for those mailboxes
$MissingArchive | Enable-Mailbox -Archive
# Kick off archiving process
$MissingArchive | ForEach {Start-ManagedFolderAssistant $_.Identity}
This does not work for some mailboxes migrated and synchronised with on-prem AD. The following script will update the AD user account to ensure the archive is enabled in Exchange Online.
# Enable online archive for shared mailbox migrated from on-premise
# Get user whose status is migrated but not with archive
$users = get-aduser -filter {msExchRemoteRecipientType -eq 97 -or msExchRemoteRecipientType -eq 1}
# Enable migrated with archive type
$users | ForEach {set-aduser $_.DistinguishedName -replace @{msExchRemoteRecipientType=6}}
# then sync users. online archive will then be create automatically