Expanding group members in Administrators Group

Welcome Forums General PowerShell Q&A Expanding group members in Administrators Group

Viewing 4 reply threads
  • Author
    Posts
    • #242642
      VT
      Participant
      Topics: 7
      Replies: 23
      Points: 37
      Rank: Member

      Hi there, I have got a script that will get list of users in Admins group in a system. Can you please share how I can get members of groups in Administrators user group in a system. I am trying to get an out like one mentioned below –

      Members in Administrators group –

      Tom Tom (AD Users)
      Harry Harry (AD Users)
      MARKETING (AD Group)
      Tim Tim (User in Marketing Group)
      Laura Laura (User in Marketing Group)

      Here is my sample script

      $Output = “C:\Temp\UserInfo.txt”

      $Servers = Get-Content -Path “C:\Temp\SystemNames.txt”

      foreach ($Servers in $Servers)

      {

      # 1. To get Local Administrators group Members

      Write-Output ” Administrators group Members for the Server mentioned above ” |out-file $Output -Append

      $localgroup = “Administrators”

      $Group= [ADSI]”WinNT://$Servers/$LocalGroup,group”

      $members = $Group.psbase.Invoke(“Members”)

      $members | ForEach-Object { $_.GetType().InvokeMember(“Name”, ‘GetProperty’, $null, $_, $null) } | Out-File $Output -Append

      }

      • This topic was modified 3 months, 1 week ago by VT. Reason: email notification option - selected
    • #242669
      Participant
      Topics: 8
      Replies: 615
      Points: 2,383
      Helping Hand
      Rank: Community Hero

      Hi V

      I would use Get-LocalGroupMember with PSRemoting.

      If you don’t have PSRemoting available, you could use WMI/CIM as well. I hope this helps.

    • #242729
      VT
      Participant
      Topics: 7
      Replies: 23
      Points: 37
      Rank: Member

      Thanks  Doug. I see the result, its in a straight line with “…” at the end. I tried to update the last line of the script as mentioned below –

      “} | select server, admins | Format-List | out-file $Output  -encoding ASCII”

      Current Output – 

      Server : Server1
      Admins : {DC\User1, DC\User2, DC\User3, DC\User4…}

      Its a output format issue, I understand, if you have any suggestions, please let me know.

    • #242810
      Participant
      Topics: 8
      Replies: 615
      Points: 2,383
      Helping Hand
      Rank: Community Hero

      If you want all the admins listed you could do

      You may want to export it as a CSV, not sure how you plan to consume it. Take care.

    • #248017
      VT
      Participant
      Topics: 7
      Replies: 23
      Points: 37
      Rank: Member

      If you want all the admins listed you could do

      Invoke-Command -ComputerName $servers -ScriptBlock { [pscustomobject]@{ Server = $env:COMPUTERNAME Admins = (Get-LocalGroupMember -Group “Administrators”) } } | select server,@{n=”admins”;e={$_.admins -join “, “}} | out-file $output -encoding ASCII You may want to export it as a CSV, not sure how you plan to consume it. Take care.

      Hi Dough, Thank you for that update, I tried I still get the same output. My apologies for the delayed reply as I was on vacation. I can post the out put tomorrow.

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