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

  • This topic has 5 replies, 4 voices, and was last updated 3 weeks ago by
    Participant
    .
Viewing 4 reply threads
  • Author
    Posts
    • #188623
      Participant
      Topics: 120
      Replies: 258
      Points: 229
      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: 1
      Replies: 1632
      Points: 3,074
      Helping Hand
      Rank: Community Hero

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

    • #188788
      Participant
      Topics: 0
      Replies: 6
      Points: 79
      Rank: Member

      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: 258
        Points: 229
        Rank: Participant

        Thank you BenT. This works well

    • #188824
      Participant
      Topics: 4
      Replies: 95
      Points: 192
      Helping Hand
      Rank: Participant

      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: 1
      Replies: 1632
      Points: 3,074
      Helping Hand
      Rank: Community Hero

      This is what I've come up with.

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

Viewing 4 reply threads
  • You must be logged in to reply to this topic.