nazir_hussain

Need help with sorting _AD_GetGroupMembers output to simple string,

2 posts in this topic

#1 ·  Posted

Need help with sorting _AD_GetGroupMembers output to simple string,

From this:
CN=Hostname01,OU=Floor,OU=Computers,OU=Mumbai,DC=Domain,DC=com
CN=Hostname02,OU=Training Computers,OU=Floor,OU=Computers,OU=Mumbai,DC=Domain,DC=com

To this:
Mumbai\Computers\Floor
Mumbai\Computers\Floor\Training Computers

I am using code:
$String = StringReplace($String, ",DC=Domain,DC=com", "")
$String = StringReplace($String, "CN=" & $Computer & ",OU=", "")
$String = StringReplace($String, ",OU=", "\")

But output is:
Floor\Computers\Mumbai
Training Computers\Floor\Computers\Mumbai

Need to reverse this or need simple & faster code using StringRegExpReplace or other.

Thanks.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <String.au3>


$FQDN1 = "CN=Hostname01,OU=Floor,OU=Computers,OU=Mumbai,DC=Domain,DC=com"
$FQDN2 = "CN=Hostname02,OU=Training Computers,OU=Floor,OU=Computers,OU=Mumbai,DC=Domain,DC=com "


$FQDN1_a =  _StringBetween($FQDN1,"CN=Hostname01,OU=Floor,OU=Computers,OU=", ",DC=Domain,DC=com")[0]
$FQDN1_b =  _StringBetween($FQDN1,"CN=Hostname01,OU=Floor,OU=", ",OU=Mumbai,DC=Domain,DC=com")[0]
$FQDN1_c =  _StringBetween($FQDN1,"CN=Hostname01,OU=", ",OU=Computers,OU=Mumbai,DC=Domain,DC=com")[0]


$FQDN2_a =  _StringBetween($FQDN2,"CN=Hostname02,OU=Training Computers,OU=Floor,OU=Computers,OU=", ",DC=Domain,DC=com")[0]
$FQDN2_b =  _StringBetween($FQDN2,"CN=Hostname02,OU=Training Computers,OU=Floor,OU=", ",OU=Mumbai,DC=Domain,DC=com")[0]
$FQDN2_c =  _StringBetween($FQDN2,"CN=Hostname02,OU=Training Computers,OU=", ",OU=Computers,OU=Mumbai,DC=Domain,DC=com")[0]
$FQDN2_d =  _StringBetween($FQDN2,"CN=Hostname02,OU=", ",OU=Floor,OU=Computers,OU=Mumbai,DC=Domain,DC=com ")[0]


MsgBox(0,"FQDN1", $FQDN1_a & "\" & $FQDN1_b & "\" & $FQDN1_c)
MsgBox(0,"FQDN2", $FQDN2_a & "\" & $FQDN2_b & "\" & $FQDN2_c & "\" & $FQDN2_d)

 

Edited by david1337

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now