Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Updated Group Reporter

Posted on March 4, 2008July 2, 2013

A few of my recent Mr. Roboto columns have been about group auditing. I first published an HTA that would report on group membership last December. Astute reader Matt V. found a bug with the way nested group memberships were being reported. Or in this case, not being reported. It turns out that if a group was a member of one other group, that membership was not reported. But if the group was nested in 2 or more groups then you'd see all the nested groups. After a little debugging I found my goof. I used ADSI to get a reference to the specified group:

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!
Set objGroup=GetObject("LDAP://" & strDN)

strDN would have a value like CN=Sales,OU=Groups,DC=Mycompany,DC=local. My mistake was in assuming that the MemberOf property would always be a collection so I was using a ForEach construct. But it is only a collection if there is more than one group. So I modified the code:

If IsArray(objGroup.MemberOf) Then
Trace "MemberOf is a collection"
For Each member In objGroup.MemberOf
Trace "found member of " & member
strMemberOf=strMemberof & " " & member & VbCrLf
Next
Else
Trace "found member of " & objGroup.MemberOf
strMemberOf=strMemberof & " " & objGroup.MemberOf & vbcrlf
End If

Because I used the same code in a followup article where I released a command line version of the tool, I had to modify that tool as well. The above code snippet is actually from the WSF version.

Anyway, both versions have now been updated and are available for download from the Mr. Roboto section of my script library. Thank you Matt for keeping me on my toes.


Behind the PowerShell Pipeline
Technorati Tags: Mr Roboto, ADSI, HTA, VBScript, LDAP

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d