Solved

Remove Parts of the Computer's Distinguished Name

Posted on 2011-09-20
7
792 Views
Last Modified: 2012-05-12
I have a script that queries an OU for all the computer and outputs the computer: CN, OS, Owner, When Created, and the distinguished name to an excel spread sheet. I'd like to remove the last two pieces of the DN so that whoever gets the spreadsheet could sort on the computer name, CN, or the OU in the event I was searching Active Directory aka DN.

Example DN: CN=PCNAME,OU=COMPUTERS,OU=FINANCE,OU=DEPT,OU=DOMAIN.
In this case I'd like to remove: CN=PCNAME,OU=COMPUTERS, and if possible the OU= before Finance as well.

Thanks!!

DoRecursive("OU=computers,OU=Finance,OU=Departments,DC=domain.com")

 
Function DoRecursive(strObjectDN)
Set objOU = GetObject("LDAP://" & strObjectDN)
objOU.Filter = Array("Computer")

Set objUser = GetObject("LDAP://" & strObjectDN)	
Set objFSO = CreateObject("Scripting.FileSystemObject")

For Each objComputer In objOU
Set objNtSecurityDescriptor = objComputer.Get("ntSecurityDescriptor")	

    Excel.Cells(counter,1).Value = objComputer.CN
    Excel.Cells(counter,2).Value = objComputer.OperatingSystem
    Excel.Cells(counter,3).Value = objNtSecurityDescriptor.owner
    Excel.Cells(counter,4).Value = objComputer.WhenCreated
    Excel.Cells(counter,5).Value = objComputer.DistinguishedName
    counter =counter +1    

Next
End Function

Open in new window

0
Comment
Question by:JB4375
  • 4
  • 3
7 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 36570377
Hi, have a look at using objComputer.Parent or objComputer.Parent.Parent to return various elements of the string.  I'm not sure whether you mean from
Example DN: CN=PCNAME,OU=COMPUTERS,OU=FINANCE,OU=DEPT,OU=DOMAIN.
In this case I'd like to remove: CN=PCNAME,OU=COMPUTERS, and if possible the OU= before Finance as well.

that you want to display just
OU=DEPT,OU=DOMAIN

or
CN=PCNAME,OU=COMPUTERS,OU=FINANCE

Rob.
0
 
LVL 1

Author Comment

by:JB4375
ID: 36573457
Sorry about that.... just OU=Department,OU=Domain, and if possible remove the "OU=" off the front of department.

That way when I output it to a spreadsheet Col1 allows me to sort on Computer Name and Col4 allows me to sort by Department.

Thanks!!
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 36573512
So something like
Excel.Cells(counter,6).Value = Mid(objComputer.DistinguishedName, InStrRev(objComputer.DistinguishedName, "OU=") + 3)

Rob.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 1

Author Comment

by:JB4375
ID: 36575829
Rob,

That's close enough to get me where I want to be.

Thanks!!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36577284
OK cool. Is there anything else you need?

Rob.
0
 
LVL 1

Author Closing Comment

by:JB4375
ID: 36580119
Yes, apparently I "need" to remember to close the question after I've been given a viable solution. LOL.

Thanks again, Rob. :)
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36580165
LOL!  No worries. Thanks for the grade.

Rob.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Lockdown of laptops 10 38
Deleting Computer From AD Still Lets me Login 1 22
LDAP and ADFS 1 23
Password Expiry 9 19
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now