JB4375
asked on
Remove Parts of the Computer's Distinguished Name
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=D OMAIN.
In this case I'd like to remove: CN=PCNAME,OU=COMPUTERS, and if possible the OU= before Finance as well.
Thanks!!
Example DN: CN=PCNAME,OU=COMPUTERS,OU=
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
ASKER
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!!
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!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rob,
That's close enough to get me where I want to be.
Thanks!!
That's close enough to get me where I want to be.
Thanks!!
OK cool. Is there anything else you need?
Rob.
Rob.
ASKER
Yes, apparently I "need" to remember to close the question after I've been given a viable solution. LOL.
Thanks again, Rob. :)
Thanks again, Rob. :)
LOL! No worries. Thanks for the grade.
Rob.
Rob.
Example DN: CN=PCNAME,OU=COMPUTERS,OU=
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=
Rob.