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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s