Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Working on script to get count of users/computers from specific OU’s and export to Excel while generating charts

$
0
0

I’ve been working on this script in some free time over the past week, and feel like I’m either overcomplicating it or am going about this all wrong.

The overall goal is to search AD under specific OU’s for users & computers, export the counts to Excel, and format them into charts based on the parent OU containing the users/computers.

In AD we have ~20 sites listed under a blanket site OU. While I can just do a blanket Get-ADUser on it, it isn’t desirable because under the sub OU’s for each site there are application/service/shared accounts that I don’t want to count. I want only users that have their own accounts created.

Here is an example breakdown of the AD structure:


Domain Name

  • Companies
    • CompanyName
      • SiteName
        • Desktop PCs
        • Laptop PCs
        • Shared Accounts
        • Service Accounts
        • Application Accounts
        • Users
      • SiteName
        • <No Users>

As mentioned above, I’m looking to just get the count of users in OU=Users for each SiteName, not those in the other user containing OU’s. Also some of the SiteName OU’s do not contain an OU=Users, so it would need to skip over those.

For the layout in Excel, I need for there to be a section for each SiteName that has the Desktop PCs/Laptop PCs/Users listed under it.

Once I have the proper data I can handle the exporting to Excel, but I’m running into issues getting the correct data in the first place. I suppose I could type out literally every full OU to search, but that defeats the purpose of using PowerShell to do this. I tried doing a foreach($SiteName in $CompanyName){if ($SiteName contains “Users”){Get-ADUser -Filter * -SearchBase “OU=Users,$SiteName”}} but it doesn’t seem to like the way I’m doing it.

Any ideas or examples I could use for doing this?

submitted by /u/hihowubduin
[link] [comments]

The post Working on script to get count of users/computers from specific OU’s and export to Excel while generating charts appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles