Excel list of users in AD Groups

Steven 0 Reputation points
2024-08-15T17:04:19.94+00:00

I have a list of user names in an excel file, I want to write a powershell script to tell if each user is in a group that contains a string in an AD group. The AD groups are all different names but contain "-String" at the end of the AD group name. I want the input to be an excel file of names to check and the output be a list of names NOT in the list.

Easy to do with PowerShell?

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,959 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,634 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,584 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 46,811 Reputation points
    2024-08-15T18:50:53.4833333+00:00

    It's relatively easy.

    First, using an Excel file directly isn't something you can do with PowerShell. You can export that Excel spreadsheet to a CSV file to remove that impediment. Or you can install the ImportExcel Powershell module and use it to work directly from the Excel file. (https://www.powershellgallery.com/packages/ImportExcel/7.8.9).

    I think the approach that would make the most sense in your description of the problem would look something like this:

    • Each AD object that is a member of any AD group has a property named "memberof". That property contains the distinguishedName of all the groups of which the user (in your case) is a direct member.
    • Get the distinguishedName property from each AD group whose name ends with "-String" and place them in an array (or a hashtable where the key is the groups DN).
    • For each user in your list, get that users "memberOf" property and check each DN in that multivalued property against the set of group DNs.
    • If the users memberOf contains none of the group DNs, then do something with that user to identify it as not being a member of any of your *-String groups.

    What I'm not sure of is the meaning of the last sentence in you question:

    I want the input to be an excel file of names to check and the output be a list of names NOT in the list.

    I'm assuming you meant ". . . NOT in any of the *-String groups."

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.