AD user properties and group membership check combined

Welcome Forums General PowerShell Q&A AD user properties and group membership check combined

Viewing 4 reply threads
  • Author
    Posts
    • #225705
      Participant
      Topics: 1
      Replies: 1
      Points: 13
      Rank: Member

      Hello,

      I have a script that gets AD user properties for new users, formats them in an HTML table and sends them out by email. I would like to add an extra property/column to the results which lists whether the user is a member of a particular group.

      Here’s the basic part of the script

      Then I was trying various combinations of the following:

      I also tried the if statement like so:

      Any ideas would be appreciated.

    • #225732
      Participant
      Topics: 17
      Replies: 1872
      Points: 3,640
      Helping Hand
      Rank: Community Hero

      Please use the PRE tags for posting code. Rather than get Properties *, specify what you want to get, it will much faster to only return what you need. User objects have a MemberOf property that contains the DN of group memberships, so you can use LIKE for a wildcard search or CONTAINS with a full DN to match, but it would be something like this:

    • #225738
      Participant
      Topics: 6
      Replies: 17
      Points: 133
      Helping Hand
      Rank: Participant

      So, the good news is, I think you’ve just overthought the problem.

      Let’s say you’re checking to see if new accounts are members of the administrators group – here’s how I would do it:

      I’m noticing your select strings going a little funky towards the end. You only need to use the Select -property @{n="";e={}} format, when you’re doing something PowerShell won’t automatically figure out. Just selecting Name,Department,Description would work fine.

    • #225741
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      Ig, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you post code or error messages or sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      That’s actually all you need:

    • #225759
      Participant
      Topics: 1
      Replies: 1
      Points: 13
      Rank: Member

      Thank you all very much! It turned out to be so simple.
      Sorry for not including the Pre tags, I was just breaking my head trying to figure out this script. I edited the original post to include them.

      Rob’s answer is probably the simplest, while Olaf’s solves it from the direction I was trying to tackle it, using If statements. Mitch’s answer is somewhere in between Rob’s and Olaf’s. All of these work great!

Viewing 4 reply threads
  • The topic ‘AD user properties and group membership check combined’ is closed to new replies.