I can successfully get the AD Users up and iterates through the list just fine. The issue lies in getting the user’s groups listed out in a table with the user. It seems like my code either isn’t resetting like it should or something is really off with my code. I’d appreciate some help to get me over the hurdle.
and the piece of relevant code taken from the html array variable is
<table class="normal">$MemberList</table>
The end file at this point is beautiful except for the group memberships which appears to be a random collection of ALL AD groups in the environment rather than just the actual ones the user belongs to. It would be helpful if I could get each group onto its own line. The sample below is from a user that belongs to 3 groups.
You’re not clearing the $Groups variable, so you’re adding every user’s groups to the same array.
You could clear it, when you first process the user:
ForEach ($NormalUser in $NormalUsers) {
$Groups = @()
...
}
But it’s considered bad practice to use += to add array members as it does not scale well because the array is destroyed and recreated with every addition.
This would be better:
I also note from your commented line, that the $NormalUsers is populated by a Get-ADUser command. That being the case, there should be no need to get the user again in your outer foreach loop. Just get the data once.
I set the suggested code in place. The GroupMembership column is certainly cleaned up. I just need to figure out why I’m not getting the “Domain Users” group, and which could address the other question as to why I’m getting
System.Object[]
on others or not all the groups. I’m sure it is in that AD-Groups logic in some fashion.
I added a line to put the Domain Users in. I only destroy and recreate the array once outside the ForEach loop so it scales still okay.
Still figuring out the systemobject thing and a few other oddities that I see (last names aren’t captured). Have to ensure the data I’m pulling is valid.
Let’s close this thread and award Gryffindor the house cup!