Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

List AD Users and All Groups in Excel

$
0
0

I Need a Script which lists all AD Useres with all their Groups and all ADGroups "not Member of" in one row in the same order. So the result is like a Matrix 

I did a Script with a Hashtable, which generates a Table with Userproperties and all ADgroups for Value and the individual Entries for Key ( and "X" for Member of).

How can I now Export the HashTable in one row for each User perhaps csv?

$Groups = @{}
$Matrix = @{}
$Users = Get-ADUser -SearchBase $uou -Filter * -Properties memberOf,description
$AGroups = Get-ADGroup -SearchBase $gou -Filter *
ForEach ($u In $Users){
  $Matrix = @{_1_NTName=$u.sAMAccountName;_2_Logon=$u.UserPrincipalName;_3_LastName=$u.Surname;_4_FirstName=$u.GivenName;_5_Description=$u.Description}
  ForEach ($ii In $AGroups){
       $bol = $null
  ForEach ($iii in $u.memberOf){
    If ($iii -eq $ii){
   $bol = $true
   break
    }
    If ($iii -ne $ii){
    $bol = $false
   }
  }
  If ($bol -eq $true){$matrix=$matrix+@{$ii.Name="X"}}
  If ($bol -eq $false){$matrix=$matrix+@{$ii.Name=""}} 
  }
 "------------"
 $Matrix.GetEnumerator() | Sort-Object Name # Export in one row to csv
 "---------"
 }

Have anyone an Idea? Thanks

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles