Jump to content

Recommended Posts

Posted

Hello,

I am not sure where to start on this, but maybe some help from the community will help. I understand how to open a file and read it with autoit. My issue is this, I need to be able to select all the data on certain lines of the file by a keyword. I have a file that has multiple lines with the word "proxyAddresses:" that starts at the beginning of each line I want, there are other lines with other information I do not want. How can I select what I want and put it into an array? 

 

Example of file

dn: CN=John Doe,OU=Techs,OU=Users,DC=foo,DC=bar
changetype: add
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
proxyAddresses: 
 X500:/o=FooBar/ou=Exchange Administrative Group (FYDI)/cn=Re
 cipients/cn=Jogn Doec52
proxyAddresses: 
 x500:/o=ExchangeLabs/ou=Exchange Administrative Group (FYSPDLT)/cn=Rec
 ipients/cn=3ab8cd9xxxxxxxxxxxxxxxxxxxxxf64e0c-John Do
proxyAddresses: sip:jdoe@foobar.com
proxyAddresses: smtp:jdoe@foobar.mail.onmicrosoft.com
proxyAddresses: SMTP:jdoe@foobar.com

 

Posted (edited)

remove the proxy text...

 

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

Local $aRetArray, $sFilePath = "Text.txt", $aArray[6], $count, $temp

_FileReadToArray($sFilePath, $aRetArray)
If @error Then Exit MsgBox(0, "Error", "Error")

For $i = 1 To UBound($aRetArray) - 1
    If StringInStr($aRetArray[$i], "proxyAddresses:") Then
        $temp = StringTrimLeft($aRetArray[$i], 15)
        $count += 1
        $aArray[$count] = $temp
    EndIf
Next

_ArrayDisplay($aArray, "1D array - count", Default, 8)

 

8)

Edited by Valuater

NEWHeader1.png

Posted (edited)

Have a little trouble not sure why I get an error at $aArray[$count] = StringStripWS($temp,1), it works then the last two that it fins it doesn't like the array.

 

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


local $user = @username
RunWait(@ComSpec & ' /c ldifde -l proxyAddresses,objectClass -f ' & $user & '.txt -r "(proxyAddresses=smtp:' & $user & '@foobar.com)"')
sleep(1000)
Local $aRetArray, $sFilePath = $user & ".txt", $aArray[6], $count, $temp

_FileReadToArray($sFilePath, $aRetArray)
If @error Then Exit MsgBox(0, "Error", "Error")

For $i = 1 To UBound($aRetArray) - 1
    If StringInStr($aRetArray[$i], "proxyAddresses:") Then
        $temp = StringTrimLeft($aRetArray[$i], 15)
        $count += 1
        $aArray[$count] = StringStripWS($temp,1)
        if ($aArray[$count] <> "") then
            msgbox(0,"",$aArray[$count])
        endif
    EndIf
Next

Text file

 

dn: CN=John Doe,OU=Valley,OU=California,OU=Agencies,DC=foo,DC=bar
changetype: add
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: user
proxyAddresses: smtp:jdoe@xxxxvalley.com
proxyAddresses: SMTP:johndoeN@xxxxvalley.com
proxyAddresses: smtp:john-doe@foobar.com
proxyAddresses: smtp:john.doe@foobar.com
proxyAddresses: 
 X500:/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Rec
 ipients/cn=3aec3f9078ee4a2a8c4c058d3df3f6c0-Elizabeth N
proxyAddresses: smtp:jdoe@xxxxvalley.com
proxyAddresses: smtp:john-doe@xxxxtent.mail.onmicrosoft.com

N/M I see that the array was set to 6 and more data was beeing added, upped it to 10 and its fine

Edited by digitalexpl0it

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
×
×
  • Create New...