Jump to content

search for string and get variable after string


 Share

Recommended Posts

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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

 

Link to comment
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
 Share

×
×
  • Create New...