Jump to content
kneze

search for string and get variable after string

Recommended Posts

kneze

hi

i use from Command Line net user /Domain UserID >> C:\temp\sample.txt to request informations about specific Domain User. Now i wil get Password last set, Password expires, password changeable and all Groups from Global Group Membership of this User to display in a MsgBox. With FUNC _readGroups i can check which position is group date of last password set but i don't know how to get needed informations as i wrote at the beginning.

Thanks in advance for any hint how can i solve it.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.3
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


#include <File.au3>

$FilePath=@ScriptDir &"\sample.txt"
$StringToSearch="Password last set"
$CaseSense=0

$Lines=_FileCountLines($FilePath)
$hFile=FileOpen($FilePath,0)

$LinesCount=_FileCountLines($FilePath)

For $i=0 To Number($Lines)
    $Test=FileReadLine($hFile,$i)
    If StringInStr($Test,$StringToSearch,$CaseSense) Then
        $foundLine = $i
        _readGroups($foundLine,$LinesCount,$i)
        ;MsgBox(0,"","The string " & $StringToSearch & " was found on line " & $i)
        ;MsgBox(0,"","Lines found: " & $LinesCount)
        ExitLoop
    EndIf
Next

FileClose($hFile)



FUNC _readGroups($foundLine,$LinesCount,$i)

   ;For $j=$foundLine To Number($LinesCount)
   $lLine=FileReadLine($hFile,$i)
   ;$split = StringSplit($lLine," ")
   $split = StringSplit(StringStripWS($lLine,1)," ")
   For $x = 1 To $split[0]
    MsgBox(0,$x,$split[$x])
Next
   ;MsgBox(0,"",$split[15]& " " & $split[16])

   ;Next



EndFunc

 

sample.txt

Share this post


Link to post
Share on other sites
Subz

" i don't know how to get needed informations as i wrote at the beginning"

What does that mean?

Personally I whould use the AD UDF that Water wrote:

 

Share this post


Link to post
Share on other sites
kneze

Hi Subz

i would like to get in a Message Box

Password last set:

Password expires:

Password changeable:

all AD Groups in which the user is member

Sample1

Sample2

Sample3

Sample4

Sample5

etc.

 

Share this post


Link to post
Share on other sites
Subz

Here is one way:

#include <Array.au3>
#include <File.au3>

Local $aFilePath
Local $sFilePath=@ScriptDir &"\sample.txt"
Local $aRemove[19]
    $aRemove[0] = ""
    $aRemove[1] = "User name"
    $aRemove[2] = "Full Name"
    $aRemove[3] = "Comment"
    $aRemove[4] = "User's comment"
    $aRemove[5] = "Country/region code"
    $aRemove[6] = "Account active"
    $aRemove[7] = "Account expires"
    $aRemove[8] = "Password required"
    $aRemove[9] = "User may change password"
    $aRemove[10] = "Workstations allowed"
    $aRemove[11] = "Logon script"
    $aRemove[12] = "User profile"
    $aRemove[13] = "Home directory"
    $aRemove[14] = "Last logon"
    $aRemove[15] = "Logon hours allowed"
    $aRemove[16] = "The command completed successfully."
    $aRemove[17] = "The request will be processed at a domain controller for domain"

$CaseSense=0

Local $iSearch
_FileReadToArray($sFilePath, $aFilePath)
    If @error Then Exit MsgBox(16, "Error", "Error reading " & $sFilePath)
For $i = 0 To UBound($aRemove) - 1
    $iSearch = _ArraySearch($aFilePath, $aRemove[$i], 0, 0, 0, 1)
        If @error Then ContinueLoop
    _ArrayDelete($aFilePath, $iSearch)
Next
For $i = UBound($aFilePath) -1 To 0 Step - 1
    If StringStripWS($aFilePath[$i], 8) = "" Then _ArrayDelete($aFilePath, $i)
Next
$aFilePath[0] = UBound($aFilePath) - 1
_ArrayDisplay($aFilePath)

 

Share this post


Link to post
Share on other sites
kneze

Hi Subz

thanks for your way.

I have tested and my code was the following;

#include <File.au3>


DIM $StringToSearch[10], $sDATVersion[10]

$FilePath=@ScriptDir &"\sample.txt"
$j = "1"
$StringToSearch[1] = "User Name"           ; $sDATVersion[1]
$StringToSearch[2] = "Full Name"           ; $sDATVersion[2]
$StringToSearch[3] = "Comment"             ; $sDATVersion[3]
$StringToSearch[4] = "Password last set"   ; $sDATVersion[4]
$StringToSearch[5] = "Password expires"    ; $sDATVersion[5]
$StringToSearch[6] = "Password changeable" ; $sDATVersion[6]
$StringToSearch[7] = "Logon script"        ; $sDATVersion[7]
$StringToSearch[8] = "Home directory"      ; $sDATVersion[8]
$StringToSearch[9] = "Last logon"          ; $sDATVersion[9]

$CaseSense=0
Global $aString = ""

$Lines=_FileCountLines($FilePath)
$hFile=FileOpen($FilePath,0)

$LinesCount=_FileCountLines($FilePath)

For $i=0 To Number($Lines)
    $Test=FileReadLine($hFile,$i)

    If StringInStr($Test,$StringToSearch[$j],$CaseSense) Then

        $foundLine = $i
        ;_readGroups($foundLine,$LinesCount,$i)
        _readGroups()
       ;MsgBox(0,"",$sDATVersion[$j])
       $j = $j + 1
       IF $j = "10" then ExitLoop
        ContinueLoop

EndIf
Next

MsgBox(0,"User INFO","User Name: " & $sDATVersion[1] & @CRLF & @CRLF & "Full Name: " & $sDATVersion[2] & @CRLF & @CRLF & "Comment: " & $sDATVersion[3] & @CRLF & @CRLF & "Password last set: " & $sDATVersion[4] & @CRLF & @CRLF & "Password expires: " & $sDATVersion[5] & @CRLF & @CRLF & "Password changeable: " & $sDATVersion[6] & @CRLF & @CRLF & "Logon Script: " & $sDATVersion[7] & @CRLF & @CRLF &"Home directory: " & $sDATVersion[8] & @CRLF & @CRLF &"Last logon: " & $sDATVersion[9])


FileClose($hFile)


;FUNC _readGroups($foundLine,$LinesCount,$i)
FUNC _readGroups()

   ;For $j=$foundLine To Number($LinesCount)
   $sString=FileReadLine($hFile,$i)


$aString = StringSplit($sString, @LF)
For $i = 1 To $aString[0]
    If StringInStr($aString[$i], $StringToSearch[$j]) Then $sDATVersion[$j] = StringStripWS(StringReplace($aString[$i], $StringToSearch[$j], ""), 8)
Next

EndFunc

 

it works. only Password last set, Password expires etc has no space between Date and Time: 06.03.201808:45:31 instead 06.03.2018 08:45:31

 

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

  • Similar Content

    • tezhihi
      By tezhihi
      I have a file (see attached file) with a string all line and this problem on here is I want to separate all $00:, $03:, $10:, $20:, $25:, $30:, $40:, $45:, $110:, $115:, $120: and $T. It's mean that each $ with value start a new line ( a new paragraph). I tried with Regular Expression in notepad++ ex:
      Find ($00:, $01:, $03: and so on) with regex (\$)([0-9]+): and replace is \r\n\1\2 (I think \r\n is @CRLF (not sure :() ) Find $T with regex (\$T)(.*?)(\$T) and replace is \1\2\r\n\3 When I try these regex to replace in notepad on StringRegexReplace the results is incorrect . I have read some example simple about regex. Please advise me how to do that with some example on autoit . The result will be in attached photo. Thanks 
      ahihi.txt

    • virhonestum
      By virhonestum
      Hey,
      I've coma accross a very odd problem. I want to download a CSV-File, and process the contents.
      This is the extremely simplyfied AutoIT-Code, given the file is already downloaded:
      $f= @ScriptDir & "\TestFile.csv" $file = FileOpen($f,0) Local $line = FileReadLine($file) MsgBox(0,"",$line) The downloaded CSV file I want to process contains something like this:
      Artikelnummer;EAN-Code;Artikelname;Artikelgewicht;Beschreibung;Kurzbeschreibung;Eigenschaften;Technische-Daten;Bild1;Bild2;Bild3;Bild4;Bild5;Bild6;Bild7;Bild8;Lieferbar;"Lieferbar Ab";Versandzeit;"UVP-Preis inkl. MwSt.";"Preis1";"Preis2";Hersteller L7335272;5420025602129; Mini Light XLR ;0.1000; JB Systems Schwanenhalsleuchte mit XLR Anschluss. ;;;;http://www.example.com/media/images/org/pic20070114153500a.jpg;;;;;;;;JA;; 1-3 Tage ;12,90;12,90;6,57; JB Systems L3320502;540207025601636; Mini Light LED BNC ;0.1000; JB Systems LED Schwanenhalsleuchte mit BNC Anschluss. ;;;;http://www.example.com/media/images/org/pic20061231171705a.jpg;;;;;;;;JA;; 1-3 Tage ;29,90;25,89;15,26; JB Systems L1332254;542002556023143; Mini Light LED XLR ;0.1000; JB Systems LED Schwanenhalsleuchte mit XLR Anschluss. ;;;;http://www.example.com/media/images/org/pic20061231171728a.jpg;;;;;;;;JA;; 1-3 Tage ;29,90;25,89;15,26; JB Systems L8302591;504200256280277; Spiegelkugel 10cm ;0.5000; JB Systems Spiegelkugel 10cm Durchmesser mit einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;http://www.example.com/media/images/org/pic20060324214825a.jpg;;;;;;;;JA;; 1-3 Tage ;5,50;4,90;2,81; JB Systems L7302932;542000256510222; Spiegelkugel 20cm ;0.8400; JB Systems Spiegelkugel 20cm Durchmesser mit einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;http://www.example.com/media/images/org/pic20060324214907a.jpg;;;;;;;;JA;; 1-3 Tage ;12,90;11,50;6,58; JB Systems L2350293;534200562064239; Spiegelkugel 30cm ;2.1300; JB Systems Spiegelkugel 30 cm Durchmesser mit einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;http://www.example.com/media/images/org/pic20060324214956a.jpg;;;;;;;;JA;; 1-3 Tage ;26,90;23,00;13,72; JB Systems L3302984;545200252024246; Spiegelkugel 40cm ;3.5000; JB Systems Spiegelkugel 40cm Durchmesser mit Sicherungsring und einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;http://www.example.com/media/images/org/pic20060324215050a.jpg;;;;;;;;JA;; 1-3 Tage ;54,90;49,00;28,00; JB Systems L9302495;542205056225600; Spiegelkugel 50cm ;5.3900; JB Systems Spiegelkugel 50cm Durchmesser mit Sicherungsring und einer hohen Dichte durch 10 x 10 mm Echtglasspiegel. ;;;;http://www.example.com/media/images/org/pic20060324215122a.jpg;;;;;;;;JA;; 1-3 Tage ;89,00;79,00;45,39; JB Systems But the message box that pops up after FileReadLine contains this:
      䅲瑩步汮畭浥爻䕁中䍯摥㭁牴楫敬湡浥㭁牴楫敬来睩捨琻䉥獣桲敩扵湧㭋畲穢敳捨牥楢畮朻䕩来湳捨慦瑥渻呥捨湩獣桥ⵄ慴敮㭂楬搱㭂楬搲㭂楬搳㭂楬搴㭂楬搵㭂楬搶㭂楬搷㭂楬搸㭌楥晥牢慲㬢䱩敦敲扡爠䅢∻噥牳慮摺敩琻≕噐ⵐ牥楳⁩湫氮⁍睓琮∻≐牥楳ㄢ㬢偲敩猲∻䡥牳瑥汬敲ੌ㜳㌵㈷㈻㔴㈰〲㔶〲ㄲ㤻M楮椠䱩杨琠塌刀㬰⸱〰〻J䈠卹獴敭猠卣桷慮敮桡汳汥畣桴攠浩琠塌删䅮獣桬畳献;㬻㭨瑴瀺⼯睷眮數慭灬攮捯洯浥摩愯業慧敳⽯牧⽰楣㈰〷〱ㄴㄵ㌵〰愮橰朻㬻㬻㬻㭊䄻㬀ㄭ㌠呡来;ㄲⰹ〻ㄲⰹ〻㘬㔷㬀䩂⁓祳瑥浳 I've attached both files I use. 
      My guess is, that there's something wrong with the encoding, but I'm not sure how to fix it.
       
      Thank you very much for your help
      - virhonestum
      Encodingtester.au3
      TestFile.csv
    • 6401integramandj
      By 6401integramandj
      I am very new to Autoit and pretty new to scripting altogether.I have a PowerShell script that pulls owner info from folders on our file share server. There are 3 owners for every folder, Domain Admin, User setup for network scanning and the user. I am trying to copy the username only from this txt file. I have gotten as far as to being able to read the lines in the txt file but can't seem to read the columns. This is what i have so far.
      #include <File.au3>
      $file = "c:\test01.txt"
      FileOpen($file, 0)
      For $i = 5 to _FileCountLines($file)
          $line = FileReadLine($file, $i)

       msgbox(0,'','the line ' & $i & ' is ' & $line & 'and the column is')
      Next
      FileClose($file)
       
      This is the outcome.....

      This is the txt file

      I am trying to copy the ABC part without the MyDomain\. I know it's line 5 and columns 11-14 of the txt file but i can't figure out how to read it. I hope i'm explaining this correctly. 
    • PINTO1927
      By PINTO1927
       
      Hello guys, I would have the need to import into the GUICtrlCreateListView all * .txt files in a folder. The * .txt files contain all of the same formatting separated by "|", the script should go on every single file and bring me back the result in the GUICtrlCreateListView. For now I only managed to upload a single file * .txt into the GUICtrlCreateListView with this code:
      Case $Button_Find $File_txt = "\\cond\UPDATE\test.txt" Dim $Array_List _FileReadToArray($File_txt, $Array_List) $Limit_Array = UBound($Array_List) - 1 For $i = 1 To $Limit_Array $All_Box = String($Array_List[$i]) GUICtrlCreateListViewItem($All_Box, $List) Next For $i2 = 0 To _GUICtrlListView_GetColumnCount($List) _GUICtrlListView_SetColumnWidth($List, $i2, $LVSCW_AUTOSIZE_USEHEADER) Next
    • PINTO1927
      By PINTO1927
      Hi Guys,
      I'm working on this project:
      $Import = GUICtrlCreateButton("Import", 15, 175, 90, 40, $WS_GROUP) $List = GUICtrlCreateListView("Name|Address|E-mail", 15, 220, 400, 363, $LVS_SORTDESCENDING) $Item1 = GUICtrlCreateListViewItem("test|test|test", $List) GUISetState(@SW_SHOW, $GUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $Exit Exit Case $Import $Table_Import = FileOpenDialog("Import list '*.txt'", @DesktopDir & "\", "Text (*.txt)") If @error Then ContinueLoop GUICtrlSetData($Item1, $Table_Import) In the text file the fields are delimited with "|" and the values are not in the same row but one below the other.
      However in the txt file the sum of the values may change.
      Can you help me?
      Thank's
×