PowerShell: Remove a single value from an Array property where it exists for multiple datasets

Scenario: You are running a get-mailbox command and you want to remove a specific array value for reporting purposes, in our case it was a InPlaceHolds value, from any mailbox where this value exists. Example: We want to remove this Hold GUID from the report for visibility to not confuse folks when they see it for each mailbox: mbxf246564cda4f41faae611cb6e6198a2f:2

Scriptlet: Here is how we did that.

#0. Collect all Mailboxes via Get-Mailbox
$AllMBX += get-exomailbox -Properties alias,LitigationHoldEnabled,InPlaceHolds,recipienttypedetails -ResultSize unlimited 



#1. Loop through AllMbx and remove the value that we do not want
$Allmbx | Where InPlaceHolds -ne $null | %{
            "$_.Name"
            $IPH = $_.InPlaceHolds
            $IPH.Remove("mbxf246564cda4f41faae611cb6e6198a2f:2") 
            }



#2. Now, when you display $allMbx, you will see that this value no longer exists for the dataset
$AllMbx  | Select Alias, InPlaceHolds
        

Leave a comment