Sign in to follow this  
Followers 0
Iznogoud

[StringSplit]Dsquery output changing into fullnames

9 posts in this topic

I am reasonable new to AutoIT, i can have learn a lot but not so much about stringreplace,stringsplit etc.

But is it possible to adjust the output of a dsquery wich is executed in a Domain enviroment to only a Fullname or Username and Lastname?

example output of a dsquery:

"CN=Remote Support,OU=Users,DC=domain,DC=local"
"CN=Ghost,OU=Users,DC=domain,DC=local"
"CN=Test user1,OU=Users,DC=domain,DC=local"
"CN=Test user2,OU=Users,DC=domain,DC=local"
"CN=Test user3,OU=Users,DC=domain,DC=local"

Is it possible to change "CN=Test user1,OU=Users,DC=domain,DC=local"

into "Test user1" ?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

that was what you got so far,

"CN=Remote Support,OU=Users,DC=domain,DC=local"
"CN=Ghost,OU=Users,DC=domain,DC=local"
"CN=Test user1,OU=Users,DC=domain,DC=local"
"CN=Test user2,OU=Users,DC=domain,DC=local"
"CN=Test user3,OU=Users,DC=domain,DC=local"

but what would be the result you want?

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

First split text into tokens then remove the "CN=", which only leaves the username.

Heres my attempt at getting the user name from a string:

Dim $Temp = StringSplit("CN=Test user1,OU=Users,DC=domain,DC=local", ",")
Dim $User = StringMid($Temp[1], 4, StringLen($Temp[1]))
MsgBox(0, "", $User)

Seems to work for me.

Edited by Emperor

Share this post


Link to post
Share on other sites

HI,

there are different possibilities. Like:

#include<Array.au3>
$s = "CN=Remote Support,OU=Users,DC=domain,DC=local" & _
"CN=Ghost,OU=Users,DC=domain,DC=local" & _
"CN=Test user1,OU=Users,DC=domain,DC=local"& _
"CN=Test user2,OU=Users,DC=domain,DC=local"& _
"CN=Test user3,OU=Users,DC=domain,DC=local"

MsgBox(0,"", _StringBetween1($s, "CN=", ","))
Dim $a = _SRE_Between($s, "CN=", ",", 1)
_ArrayDisplay($a , "Array")


Func _StringBetween1($s_String, $s_Start = 0, $s_End = 0)
    $s_Start = StringInStr($s_String, $s_Start) + StringLen($s_Start)
    Return StringMid($s_String, $s_Start, StringInStr($s_String, $s_End) - $s_Start)
EndFunc   ;==>_StringBetween1

Func _SRE_Between($s_String, $s_Start, $s_End, $i_ReturnArray = 0); $i_ReturnArray returns an array of all found if it = 1, otherwise default returns first found
    $a_Array = StringRegExp($s_String, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If Not @error And Not $i_ReturnArray And IsArray($a_Array) Then Return $a_Array[0]
    If IsArray($a_Array) Then Return $a_Array
EndFunc

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

First split text into tokens then remove the "CN=", which only leaves the username.

Heres my attempt at getting the user name from a string:

Dim $Temp = StringSplit("CN=Test user1,OU=Users,DC=domain,DC=local", ",")
Dim $User = StringMid($Temp[1], 4, StringLen($Temp[1]))
MsgBox(0, "", $User)

So long,

Mega

:D thats a script where you need some experience wich i don't have yet. Other words, i don't understant that script at all, too hard for me.

I thought there was an easy way to do it :D

Edited by Iznogoud

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

When you do your DSQUERY command, use the "-o rdn" option to give only the relative DN, which in you examples would be the following:

Command:

DSQUERY user domainroot -o rdn

Results:

"Remote Support"

"Ghost"

"Test user1"

"Test user2"

"Test user3"

I have used this same command for getting just the user's names. The same works for getting computers connected as well. Hope this helps.

KilRoy

Edited by KilRoy

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi,

it isn't that hard.

Too func _StringBetween1 and _SRE_Between.

Both are able to find a string between a start and end point.

_SRE_Between also can return an array with all found occurances.

Like I did here

Dim $a = _SRE_Between($s, "CN=", ",", 1)

This is only for displaying the retuned array.

_ArrayDisplay($a , "Array")

That's all.

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

When you do your DSQUERY command, use the "-o rdn" option to give only the relative DN, which in you examples would be the following:

Command:

DSQUERY user domainroot -o rdn

Results:

"Remote Support"

"Ghost"

"Test user1"

"Test user2"

"Test user3"

I have used this same command for getting just the user's names. The same works for getting computers connected as well. Hope this helps.

KilRoy

How stupid, i missed that option. The only what i need to figure out is removing the " ".

-edit-

With StringTrimLeft StringTrimRight :D

Hi,

it isn't that hard.

Too func _StringBetween1 and _SRE_Between.

Both are able to find a string between a start and end point.

_SRE_Between also can return an array with all found occurances.

Like I did here

Dim $a = _SRE_Between($s, "CN=", ",", 1)

This is only for displaying the retuned array.

_ArrayDisplay($a , "Array")

That's all.

So long,

Mega

Sorry, but i know its easy for you, but i am trying to understand but for now its to difficult. Edited by Iznogoud

Share this post


Link to post
Share on other sites

With StringTrimLeft StringTrimRight :D

Or you could StringReplace

i.e.

StringReplace($output, '"', "") ; assumes you already have your output read into a string named $output

KilRoy

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
Sign in to follow this  
Followers 0