How to get all users in Active directory and Exchange using PowerShell

When we are using Exchange PowerShell and we want to retrieve all mailboxes we can use
Get-mailbox –resultsize unlimited otherwise you will get only 10000 mailboxes.
PS C:\> Get-Mailbox -ResultSize Unlimited
Name    Alias  Database      ProhibitSendQuota   ExternalDirectoryObjectId                
—-    —-   ——-        —————–    ———————
If you want to filter the query you can use
PS C:\> Get-Mailbox | ?{$_.Office -eq ‘US’}
The question mark stands for “where-object” and it’s a way to short the query.
For Active Directory is a quite different, if you want to retrieve all users you have to use
  Get-AdUser –Filter * -Properties *
If you want to filter the query you can use
Get-AdUser –Filter * -Properties Department | where-object {$_.Department –eq “IT”}
In the same way as before, you can use ? also
  Get-AdUser –Filter * -Properties Department | ?{$_.Department –eq “IT”}

Leave a comment