Avatar of Tom Powers
Tom Powers

asked on 

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

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.
Active DirectoryVisual Basic.NET* group membership

Avatar of undefined
Last Comment
Tom Powers
Avatar of Tom Powers
Tom Powers

ASKER

I'm back to show errors and screenshots. OK this is just a stoppage Com Exception User generated imageBut here  I don't no why this errorsout I'm just trying to populate a listview WITH THIS dirEntry.Path = "LDAP://OU=Unified Data Centers,OU=Groups Application,DC=one,DC=ads,DC=che,DC=org"

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 = "LDAP://OU=Unified Data Centers,OU=Groups Application,DC=one,DC=ads,DC=che,DC=org"
        dirEntry.Username = "username"
        dirEntry.Password = "Password"

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

        lvGlobal.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("Image")(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


Is there anyway to databindn or Sync up a combobox with same data in a listview Checkout  Pics
User generated image
COM Exception

What I'd like to have  syncronize are
User generated imageUser generated imageUsing this distinguished name for current  AD  Groups
User generated image
And  here is my Global group that I need to pull by  itself with goal being to add some of  these groups to a current user  profile that  is it please don't run for the hills.
User generated imageLove  to hear  from you even if  it is just one suggestion cause one suggestion is one closer to the end result. God Bless thee.
ASKER CERTIFIED SOLUTION
Avatar of Tahir Qureshi
Tahir Qureshi
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Tom Powers
Tom Powers

ASKER

Nice Code I got someof what i need from your code. Thank You
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo