troubleshooting Question

Need Help I cannot Get a User's Group Memberships to display and Of course I can't get Global OU Group to display using Active Directory and VB.NET 2017

Avatar of Tom Powers
Tom Powers asked on
Active DirectoryVisual Basic.NET* group membership
3 Comments1 Solution175 ViewsLast Modified:
This has me so Worn out I can get OU  of users to display in ComboBox and In a ListView but I cannot get a Domain User to display their Group Membership in a Listview I want  to be able to add  Group Memberships from a Global OU to a User's Profile as well as Remove Groups that they are a Member of I'm using VB.NET 2017 Beta. And I am wondering can a selection also sort to the same Username in a Listview neither uses databinding. If you are  confused  allow me to show off my  faulty code and ScreenShots  so you know what I am aiming  for The reason is I'm using Active Directory and that is why  I don't have everything Binding unless that can be done. I never  suggest that I am a expert just  trying  to automate a  few Tasks to make work a little easier and maybe get Hired  instead of being  a lousy  Contractor. Anyway here is code that grabs  Username, name and Distinguished name.
 Public Sub ADRETRIEVE()
        ' On Error GoTo Next
        Dim dirEntry As DirectoryEntry = New DirectoryEntry()
        ' NOTE: This path should be comma delimited, not semi-colon delimited
        ' Each label in the domain name should be a separate Domain Component (DC)
        dirEntry.Path = "LDAP://OU=NAZ,OU=User Accounts,DC=one,DC=ads,DC=che,DC=org"
        ' dirEntry.Username = "ONE\Powerst9"
        '  dirEntry.Password = "Megadeth666$"

        Dim mySearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
        ' This value can be passed in the constructor if preferred.
        mySearcher.Filter = "(objectClass=Person)"
        mySearcher.PageSize = 1001

        For Each resEnt As SearchResult In mySearcher.FindAll()

            tscmbUsers.Items.Add(resEnt.Properties("Name")(0).ToString())
            Dim lvi As ListViewItem = New ListViewItem()
            ' Dim listItem As New ListViewItew.Add(p.ProcessName.ToString())
            lvi.ImageIndex = 0
            lvi.SubItems.Add(resEnt.Properties("Name")(0).ToString())
            lvi.SubItems.Add(resEnt.Properties("sAMAccountName")(0).ToString())
            lvi.SubItems.Add(resEnt.Properties("Distinguishedname")(0).ToString())
            ' lvi.SubItems.Add(resEnt.Properties("phone")(0).ToString())
            ' List box is a bit simple for these unless I missed something
            ' lbADUsers.Items.Add(resEnt.Properties("sAMAccountName")(0).ToString())
            ' tscmbUsers.Items.Add(resEnt.Properties("aDSPath")(0).ToString())
            ' And this one needs some work unless you're attaching to every object within the directory.
            ' lbADUsers.Items.Add(resEnt.Properties("objectGUID")(0).ToString())
        Next
        txtNazUsers.Text = tscmbUsers.Items.Count

    End Sub
OK Know this is a Global OU with Group I want to pull all Groups from but I get  a Com Unspecified Error
Public Sub ADGlobal()
        ' On Error GoTo Next
        Dim dirEntry As DirectoryEntry = New DirectoryEntry()
        ' NOTE: This path should be comma delimited, not semi-colon delimited
        ' Each label in the domain name should be a separate Domain Component (DC)
        dirEntry.Path = "OU=Unified Data Centers,OU=Groups Application,DC=one,DC=ads,DC=che,DC=org"
        dirEntry.Username = "ONE\Powerst9"
        dirEntry.Password = "Megadeth666$"

        Dim mySearcher As DirectorySearcher = New DirectorySearcher(dirEntry)
        ' This value can be passed in the constructor if preferred.
        mySearcher.Filter = "(objectClass=group)"
        mySearcher.PageSize = 1001
        lvGroups.Columns.Add("Image", 100, HorizontalAlignment.Center)

        lvGroups.Columns.Add("Global Group Name", 650, HorizontalAlignment.Center)

     For Each resEnt As SearchResult In mySearcher.FindAll()

            ' tscmbUsers.Items.Add(resEnt.Properties("Name")(0).ToString())
            Dim lvi As ListViewItem = New ListViewItem()
            ' Dim listItem As New ListViewItew.Add(p.ProcessName.ToString())
            lvi.ImageIndex = 1
            ' lvi.SubItems.Add(resEnt.Properties("Name")(0).ToString())
            lvi.SubItems.Add(resEnt.Properties("sAMAccountName")(0).ToString())
            lvGlobal.Items.Add(lvi)
            ' lvGroups.Sort(resEnt.Properties("Name")(0).ToString())
            lvGlobal.EndUpdate()
        Next
        txtNazUsers.Text = tscmbUsers.Items.Count
    End Sub
Not grabbing Global OU  I'm remotted into my PC at  Work I'll be back after areboot no memory to take screenshots.
ASKER CERTIFIED SOLUTION
Tahir Qureshi
System Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros