none
How to export all AD groups and show only members that are enabled

    Question

  • Hello,

    I have grabbed someone else's script from another site and have been trying to alter it but to no avail.  Basically I want to export into a .csv file all of the AD security groups and any associated members that are enabled. 

    The following script exports security groups and all their members, however I'm just chasing the security groups and only enabled members.  

    TIA

    Import-Module ActiveDirectory

    $Groups = (Get-AdGroup -filter * | Where {$_.name -like "**"} | select name -ExpandProperty name)

    $Table = @()

    $Record = @{
      "Group Name" = ""
      "Name" = ""
      "Username" = ""
    }


    Foreach ($Group in $Groups) {

      $Arrayofmembers = Get-ADGroupMember -identity $Group | select name,samaccountname

      foreach ($Member in $Arrayofmembers) {
        $Record."Group Name" = $Group
        $Record."Name" = $Member.name "Enabled -ne $false'
        $Record."UserName" = $Member.samaccountname
        $objRecord = New-Object PSObject -property $Record
        $Table += $objrecord

      }
    }

    $Table | export-csv "C:\Temp\GroupReport.csv" -NTI



    • Edited by sumsysadmin Thursday, July 12, 2018 5:34 AM
    Thursday, July 12, 2018 5:28 AM

All replies