I want to get the distinguished name of the current computer. That works:
Dim objSysInfo, objComp, arr, UCID
Set objSysInfo = CreateObject("ADSystemInfo")
' Current computer
Set objComp = GetObject("LDAP://" & objSysInfo.ComputerName)
DN = objComp.distinguishedName
But I only want to save a part of the distinguished name in a new variable.
For example: The distinguished name is "OU=X, OU=Y, OU=THAT, DC=A, DC=B, DC=C"
I just need "THAT" for my variable. It is always on the fourth position beginning from the right side.
How do I do this? I started with this...
OU= Split (DN, ",")
Thank you very much!!!
If you check the documentation for Split, you will see that it returns an array (zero-based index). Therefore, you need to split on ,
and get the third element (index 2), and then split that result on =
and get the second element (index 1):
OU = Split(Split(DN,",")(2),"=")(1)