We help IT Professionals succeed at work.
Get Started

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

174 Views
Last Modified: 2018-05-24
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

Open in new window

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

Open in new window

Not grabbing Global OU  I'm remotted into my PC at  Work I'll be back after areboot no memory to take screenshots.
Comment
Watch Question
System Analyst
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE