Tuesday, August 13, 2019

Users Mailbox status


Quick post about querying a users mailbox status

https://answers.microsoft.com/en-us/msoffice/forum/msoffice_o365admin-mso_exchon-mso_o365b/recipient-type-values/7c2620e5-9870-48ba-b5c2-7772c739c651


This command returns all the users with migrated mailboxes

get-aduser -SearchBase "OU=OU2,OU=OU1,OU=OU0,DC=corp,DC=ad,DC=name,DC=com" -Properties msExchRemoteRecipientType -Filter {name -like "*"} | ?{$_.msExchRemoteRecipientType -eq 4} | select name,samaccountname,msExchRemoteRecipientType 

Friday, August 2, 2019

Function that calls itself

This was an interesting function that I've come across.  It calls itself to work out the list of reports of a user and the reports of any of their reports from a particular AD arrangement where users' managers are held in a manager field.........! er yes, you can read that again now.



function Get-DirectReports([string] $Dn) {
    $Reports = Get-ADUser -LDAPFilter "(&(manager=$dn)(mail=*))" -Properties "mail", "title" -SearchBase "OU=EUC,DC=corp,DC=ad,DC=domain,DC=com"

    if ($Reports) {
        foreach ($Report in $Reports) {
                Write-Output $Report.DistinguishedName

            if ($Report.DistinguishedName -ne $Dn) {
                Get-DirectReports $Report.DistinguishedName
            }
        }
    }
}