antmar904 Posted February 15, 2018 Posted February 15, 2018 Hi am using the AD UDF by @water trying to get a list of users in a certain group however the list of users that gets returned has the FQDN and I would like to return only their Name in this case "John Doe". I am trying to use StringRegExp to get that but I can't get it to work. Here is a test string: CN=John Doe,OU=Standard,OU=Users
Ascer Posted February 15, 2018 Posted February 15, 2018 You can try with _StringBetween function like this: #include <String.au3> Local $sString = "CN=John Doe,OU=Standard,OU=Users" Local $aName = _StringBetween($sString, "CN=", ",") If IsArray($aName) Then ConsoleWrite("Name: " & $aName[0] & @CRLF) Else ConsoleWrite("Name not found." & @CRLF) EndIF
antmar904 Posted February 15, 2018 Author Posted February 15, 2018 Not working #RequireAdmin #include <AD.au3> #include <StringConstants.au3> #include <String.au3> _AD_Open("user", "pass") If @error Then MsgBox(0, "", "Error" & @error & "Extended" & @extended) Exit EndIf Local $Users = _AD_GetGroupMembers("ESISoftwareUsers") If @error Then MsgBox(0, "", "Error" & @error & "Extended" & @extended) Exit EndIf _ArrayDisplay($Users) ;Debug For $i = 1 To UBound($Users) - 1 Local $Name = _StringBetween($Users[$i], "CN=", ",") ConsoleWrite($Name & @CRLF) Next _AD_Close() I'm missing something
TheXman Posted February 15, 2018 Posted February 15, 2018 You could try something like: #include <Constants.au3> #include <Array.au3> example() Func example() Const $kDATA = "CN=John Doe,OU=Standard,OU=Users" Local $aArray = StringRegExp($kDATA, "\bCN=([^,]*)", $STR_REGEXPARRAYMATCH) _ArrayDisplay($aArray) EndFunc youtuber 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
youtuber Posted February 15, 2018 Posted February 15, 2018 if the right part is fixed CN=(.*)(?:,OU=Standard,OU=Users)
antmar904 Posted February 15, 2018 Author Posted February 15, 2018 I'm having issues looping through the array and I'm getting a blank message box with nothing. #RequireAdmin #include <AD.au3> #include <StringConstants.au3> #include <String.au3> #include <Array.au3> _AD_Open("", "") If @error Then MsgBox(0, "AD Connection", "Error" & @error & "Extended" & @extended) Exit EndIf Local $Users = _AD_GetGroupMembers("ESISoftwareUsers") If @error Then MsgBox(0, "Get Group Members", "Error" & @error & "Extended" & @extended) Exit EndIf ;_ArrayDisplay($Users) ;Debug For $i = 1 To $Users[0] Local $Name = _StringBetween($Users[$i], "CN=", ",") MsgBox(0, "", $name) Next _AD_Close()
TheXman Posted February 15, 2018 Posted February 15, 2018 According to the help file, _StringBetween returns "a 0-based array - element [0] contains the first found string". change: Local $Name = _StringBetween($Users[$i], "CN=", ",") MsgBox(0, "", $name) To: Local $aName = _StringBetween($Users[$i], "CN=", ",") MsgBox(0, "", $aName[0]) The help file is your friend CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
antmar904 Posted February 15, 2018 Author Posted February 15, 2018 (edited) 1 hour ago, TheXman said: According to the help file, _StringBetween returns "a 0-based array - element [0] contains the first found string". change: Local $Name = _StringBetween($Users[$i], "CN=", ",") MsgBox(0, "", $name) To: Local $aName = _StringBetween($Users[$i], "CN=", ",") MsgBox(0, "", $aName[0]) The help file is your friend Hi @TheXman I am receiving this error: "C:\Temp\AD.au3" (25) : ==> Subscript used on non-accessible variable.: MsgBox(0, "", $Name[0]) MsgBox(0, "", $Name^ ERROR #RequireAdmin #include <AD.au3> #include <StringConstants.au3> #include <String.au3> #include <Array.au3> #include <AutoItConstants.au3> _AD_Open("", "") If @error Then MsgBox(0, "AD Connection", "Error" & @error & "Extended" & @extended) Exit EndIf Local $Users = _AD_GetGroupMembers("ESISoftwareUsers") If @error Then MsgBox(0, "Get Group Members", "Error" & @error & "Extended" & @extended) Exit EndIf _ArrayDisplay($Users) ;Debug For $i = 0 To UBound($Users) - 1 Local $Name = _StringBetween($Users[$i], "CN=", ",") MsgBox(0, "", $Name[0]) Next _AD_Close() Edited February 15, 2018 by antmar904
TheXman Posted February 15, 2018 Posted February 15, 2018 (edited) I didn't add any error checking. You probably are encountering a line which has no matches. You need to ensure that you have a valid array result before referencing an array element. You can use IsArray() or checking to see if the _StringBetween function succeeded. Edited February 15, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
antmar904 Posted February 16, 2018 Author Posted February 16, 2018 Wish I found _AD_FQDNToSamAccountName before trying RegEx or StringSplit This is working for me. Thanks again all. expandcollapse popup#RequireAdmin #include <AD.au3> #include <StringConstants.au3> #include <String.au3> #include <Array.au3> #include <AutoItConstants.au3> _AD_Open("user", "pass") If @error Then MsgBox(0, "AD Connection", "Error" & @error & "Extended" & @extended) Exit EndIf Local $Users = _AD_GetGroupMembers("ESISoftwareUsers") ;Returns the users FQDN. Exp: CN=First Last,OU=Standard,OU=Users,OU=Mexico,DC=na,DC=domain,DC=com If @error Then MsgBox(0, "Get Group Members", "Error" & @error & "Extended" & @extended) Exit EndIf ;_ArrayDisplay($Users) ;Debug For $i = 1 To UBound($Users) - 1 Local $Name = _AD_FQDNToSamAccountName($Users[$i]) If @error Then MsgBox(0, "_AD_FQDNToSamAccountName error", "Error" & @error) Exit EndIf Local $Results = _AD_IsObjectDisabled($Name) If $Results = @error Then ConsoleWrite($Name & " - enabled" & @CRLF) Else ConsoleWrite($Name & " - disabled" & @CRLF) EndIf Next _AD_Close()
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now