Import nested OrganizationalUnit from LDAP as tree with thier Object ID

Hi,
I am making a program with Delphi 2007 to import Active Directory users along with their OrganizationalUnit .
When I import a user, I need to get his OrganizationalUnit and then build tree for OrganizationalUnit and I need teh ogjectGUID for each OrganizationalUnit  as well.

example:
User "Kifah Najem" exists under OU Staff\Finance\A/C Payable as bellow distinguishedName
"CN=Kifah Najem,OU=A/C Payable,OU=Finance,OU=Staff,DC=kifah,DC=com,DC=sa"

So the result for OU should be as following

-Staff (OgjectGUID)
----Finance (OgjectGUID)
--------A/C Payable (OgjectGUID)

so this is a nested tree as it is in the Active directory, but for every entry I have the ObjectGUID.

Currently:
I can run the query and get the distinguishedName, as well I can parse the distinguishedName and get all OUs from the distinguishedName, but how to get the ObjectGUID for every OU
infokifahAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
The easiest way to accomplish this is using the Get-ADOrganizationalUnit cmdlet.

Import-module activedirectory
Get-ADOrganizationalUnit -Filter * | select name, ObjectGuid

Open in new window


This will get you the GUID for all of your Organizational Units in Active Directory.

Will.

Open in new window

0
infokifahAuthor Commented:
I am using Delphi, and ADO...
So I am using SQL query like

select distinguishedName, ObjectGUID, name
from 'LDAP://172.16.199.190/dc=kifah, dc=com, dc=sa'
where objectclass='OrganizationalUnit'
0
infokifahAuthor Commented:
I found the solution.

I have to parse the distinguishedName field, and extraxt all OU values and build the tree
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert GOracle dbaCommented:
have you fixed the workaround for 1000 entries ?

if you haven't ... then you'll only get 1000 users ... or ou's

the latter will probably not be a problem :)
0
infokifahAuthor Commented:
The answers was not correct at all, since I was using SQL query, and the solution submitted uses windows tools or some other ready made tool
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.