Grab a list of AD Computers; determine if they are a member of this (1) secgroup

Welcome Forums General PowerShell Q&A Grab a list of AD Computers; determine if they are a member of this (1) secgroup

Viewing 4 reply threads
  • Author
    Posts
    • #188623
      Participant
      Topics: 120
      Replies: 260
      Points: 238
      Rank: Participant

      I have a set of computers in a txt file:

      $members = Get-Content .\list.txt

      How would I leverage this variable and query a known Security Group (MySecGroup) to see if any of those computers are members? and tell me True or False?

      thank you

    • #188626
      Participant
      Topics: 5
      Replies: 2368
      Points: 5,987
      Helping Hand
      Rank: Community MVP

      Have you tried to search for a solution? What have you tried so far?

    • #188788
      Participant
      Topics: 0
      Replies: 8
      Points: 104
      Rank: Participant

      This is what I’ve come up with. There may be a better way of doing it.

      $List = Get-Content .\list.txt
      $GroupMembership = Get-ADGroupMember -Identity MySecGroup | select-object -expandproperty name
      $Report = @()
      
      foreach ($member in $GroupMembership)
      
      {
      
          if($list -contains $member)
          {
         $Report += [psCustomObject]@{
         'ComputerName' = "$member"
         'Status' = "$true"}
          }
      
      }
      
      foreach ($member in $List)
      {
          if($GroupMemberShip -notcontains $member)
          
          {
          $Report += [psCustomObject]@{
         'ComputerName' = "$member"
         'Status' = "$False"}
          }
      
      }
      
      Write-Output $Report
      
      • #189208
        Participant
        Topics: 120
        Replies: 260
        Points: 238
        Rank: Participant

        Thank you BenT. This works well

    • #188824
      Participant
      Topics: 5
      Replies: 106
      Points: 273
      Helping Hand
      Rank: Contributor

      how about

      $list = get-content .\users.txt
      $secGroupMembers = Get-ADGroupMember ‘domain admins’ -Recursive | select -ExpandProperty samaccountname
      
      foreach ($user in $list) {
      [psCustomObject][ordered]@{
      ‘samAccountName’ = $user
      ‘inSecGroup’ = $secGroupMembers -contains $user
      }
      }
      
    • #189214
      Participant
      Topics: 5
      Replies: 2368
      Points: 5,987
      Helping Hand
      Rank: Community MVP

      This is what I’ve come up with.

      Don’t you feel like you just made someones homework for free? 😉

Viewing 4 reply threads
  • The topic ‘Grab a list of AD Computers; determine if they are a member of this (1) secgroup’ is closed to new replies.