Listing 1: Code to Dynamically Query Mailbox Information $exServer | ForEach-Object { $_exServer = $_ $exStorageGroup | ForEach-Object { $_exStorageGroup = $_ ([string]$_exStorageGroup.properties.distinguishedname).split(",") | ForEach-Object { if ($_exStorageGroup -match $_exServer.properties.name) { $__exServer = $_exServer.properties.name $__exStorageGroup = $_exStorageGroup.properties.name $wql = "select * from Exchange_mailbox where (servername='" + ' $__exServer + "') and (storagegroupname='" + $__exStorageGroup + "')" $exmb = Get-WmiObject -namespace root\microsoftexchangev2 -query $wql -computer $__exServer $exmb | ForEach-Object { $_.MailboxDisplayName, $_.Size, $_.TotalItems } } } } }