I'm trying to build out a script that adds Exchange Online mailboxes that do not have an InPlaceHold property that matches the GUID of one of multiple Security and Compliance Retention Policies (this list needs to dynamically change as more and more employees are added, as you can only have 1000 mailboxes per policy).
However, I'm getting burned by the Where-Object statement. I've tried -notmatch, -notcontain, and -notin, and I always am returned the entire count of all the mailboxes in my $AllE3Mbxs.
$E3sNeedPolicy = $AllE3Mbxs | Where-Object {$_.InPlaceHolds -notmatch $E3PolicyGuidsClean}
I get the list of mailboxes as such:
$AllE3Mbxs = Get-EXOMailbox -PropertySets All -ResultSize Unlimited -Filter{(PersistedCapabilities -like "bpos_s_enterprise") -AND (PersistedCapabilities -notlike "bpos_s_o365pam")}
An example of the output (focusing on InPlaceHolds):
The GUIDs from the Retention Policies as such:
$AllRetentionPolicies = Get-RetentionCompliancePolicy
$E3Policies = $AllRetentionPolicies | Where {$_.Name -like "Exchange Retention Policy*"} | Sort-Object -Property Name
$E3PolicyGuids = $E3Policies.GUID
$E3PolicyGuidsClean = @()
Foreach($GUID in $E3PolicyGuids.GUID){
$E3PolicyGuidsClean += $GUID.Replace("-","")
}
The GUIDs are returned as such. I have to clean them up so they'll match the formatting of how the mailboxes store it.