Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Active Directory and PowerShell

Thread: AD Tricks: How many objects do you have in your AD, part 2


Permlink Replies: 0 - Pages: 1
Andrei Polevoi [Quest]


Posts: 982
Registered: 8/9/06
AD Tricks: How many objects do you have in your AD, part 2
Posted: Apr 16, 2007 11:52 AM
  Click to reply to this thread Reply

For thefirst part, please refer to http://powergui.org/thread.jspa?threadID=2701&tstart=0.

 

(This post providesinformation on how you can use Management Shell for AD from Quest Software todo various management tasks for your Active Directory. For a quick introductioninto Management Shell for AD, please refer to: http://powergui.org/thread.jspa?threadID=2700&tstart=0)

 

Let's try somethingreal.

 

For alluser accounts, let's count users for each department:

(I reallyrecommend trying 100 as size limit first)

 

PSC:\> Get-QADUser -sl 1000000 | Group-Object -property Department -noelement| Sort-Object -Descending -Property Count

 

CountName

---------

  623 R&D

  588

  296 Marketing

  292 Presales

  284 Inside/Geo/Reg Sales

  222 Support

  170 Consulting Services

  124 Named Accounts

  107 Management-Sales

   92 Admin-Sales

   81 General Accounting

   80 Channels

[...]

 

What we didhere, we build a list of all users in domain, then group them by Departmentproperty using build-in cmdlet Group-Object and then sort the results descendingby count.

 

To sort bydepartment name, execute the following:

Get-QADUser-sl 1000000 | Group-Object -property Department -noelement | Sort-Object -PropertyName

 

 

We can dothe same for other attributes.

 

Let's seehow many employees are working in each city:

PS C:\>Get-QADUser -sl 1000000 | Group-Object -property City-noelement | Sort-Object -Descending -Property Count

 

Count Name

----- ----

  160 NewYork

   58 Toronto

   31 Warrenville

    [...]

 

To countmailboxes per each mailbox store, use homeMDB attribute. As homeMDB does not presentedin default property list returned by Get-QADUser cmdlet, use the {$_.DirectoryEntry.homeMDB}as property name for the workaround:

PS C:\>Get-QADUser -sl 100 | Group-Object -property {$_.DirectoryEntry.homeMDB}-noelement | Sort-Object -Descending -Property Count

 

Count Name

----- ----

   48

    7 CN=Mailbox Store (IRVP...

    5 CN=Mailbox Store 3 (AL...

    5 CN=Mailbox Store (UKBM...

    5 CN=Mailbox Store 3 (AL...

    4 CN=Mailbox Store 3 (NY...

 
 

A quick explanationfor the  "{$_.DirectoryEntry.homeMDB}"here. This is actually a very small piece of code that first access the DirectoryEntryproperty of the object passed though the pipe (the object returned byGet-QADUser cmdlet). Then, it access the homeMDB property of theDirectoryEntry. With this workaround you can access any AD attribute.



Regards,
Andrei [Quest]
This posting is provided "AS IS" with no warranties, and confers no rights

Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums