#209774 - 2015-01-05 09:48 AM
problem extracting stuff from AD (2008R2) and compare to file with readline
|
Curious
Getting the hang of it
Registered: 2004-02-16
Posts: 61
|
Hey folks!
Happy New year btw.
I've been using - for some time - a script that makes some default outlook signatures based on predefined criterias. This has been working fine.
My problem is that this is running EVERY time a user logs on their system, meaning (since it's opening word, writing ++) this takes some time each time the script is running. And.. all of us wants logon scripts to be as fast and minimal as possible.
In this regard I'm modifying the script. What happens is that the first time the user logs on; things are collected from AD, to be written to a file. Next time the script checks for this existing file; comparing it to changes in AD. If changes detected; new signature is being generated, if else - nothing, except for some logging. There's also a routine to check on which physical machines the signature has been generated. If it's a machine not listed in the file, the signature is also generated.
This means that most of the time the script is executed within a sec or two.
Everything works pretty much as I intended; apart from one thing: When I extract the mobilephone (mobile in AD, found under 'Telephones' when looking in AD Users and Comp), comparing this value against the file, I'm ALWAYS getting the value to be different from the one in AD, even though I'm comparing it against the value in the file which was WRITTEN from the value in AD the last time.
Obviously I'm doing something wrong, but just can't see what it is. BTW I have the same problem with the value of the user's homepage (wwwhomepage in properties AD).
I'm definately not the best scripter, so you bright heads would probably do things better and easier, but the script works as intended - except from this things that are really bugging me.
Here's an extraction of the code:
$x = WriteLine( 1 , @time + " ----> " + "Starter seksjonen for å lage standardisert signatur i Outlook" + @CRLF)
If NOT Exist ("\\BK-Dc1\netlogon") $AdServer = '\\BK01'
Else $AdServer = '\\BK-DC1'
EndIf
$NetLogon = $AdServer + '\Netlogon'
$Netlogon = $AdServer +'\Netlogon'
$Filer = $NetLogon + '\Filer'
$Log = $Netlogon + "\Logger"
$klokkeslett = @Time
$klokkeslett = replace($klokkeslett, ":", ".", 1, -1)
If NOT @LOGONMODE
Break on
EndIf
CLS
At (1,0) "Lager standardisert outlook-signatur..."
Sleep 0.1
;Get data from AD
;Open ADSystemInfo object
$objSysInfo = CreateObject("ADSystemInfo")
;Get the username from AD.
$strUser = $objSysInfo.UserName
;Get the users deatils using LDAP.
$objUser = GetObject("LDAP://" + $strUser)
;Get the users full name.
;$strName = $objUser.FullName
;Stokket litt om på hvordan navn skal vises : Fornavn Etternavn
$strName = $objUser.Givenname + " " + $objUser.sn
;Get the users title.
$strTitle = $objUser.Title
;Get the users default reply e-mail address.
$strMail = $objUser.mail
;Get the users department.
$strDepartment = $objUser.Department
;Get the users company name.
$strCompany = $objUser.Company
;Get the users phone number.
$strPhone = $objUser.telephoneNumber
;Get the users mobile phone number
$strMobile = $objUser.mobile
;Get the users homepage.
$strWeb = $objUser.wWWHomePage
; In a terminalserver-environment we generate new signature if the control-file doesn't exist
if not exist ("%appdata%\OutlookSignature.txt")
Run "%comspec% /c print > %appdata%\OutlookSignature.txt"
$x = MakeNewSignature() ; Call the function to generate signature
EndIf
;Check for file identifying the user, to use this as reference for comparing values
if exist ("$Log\OutlookSignature\@userid.txt")
if open (8, "$Log\OutlookSignature\@userid.txt") = 0
;$x = ReadLine(8)
do
;WHILE @ERROR = 0
$counter = $Counter + 1
? $Counter
$x = ReadLine(8)
? "Line read: [" + $x + "]"
vartypename ($x)
if $x = $strName or $x = $strTitle or $x = $strMail or $x = $strDepartment or $x = $strCompany or $x = $strPhone or $x == strMobile or $x = strWeb
$Change = "no"
else
$Change = "yes"
$MakeNewSignature = "yes"
Endif
? "$$x : " + $x
? "$$Change : " + $Change
?"$$MakeNewSignature :" + $MakeNewSignature
sleep 3
cls
Until $Counter = 8
while @error = 0
$x = ReadLine(8)
? "Line read: [" + $x + "]"
if $x = @wksta or left(@wksta,5) = "BK-TS"
$MachineExist = "yes"
endif
LOOP
Close (8)
? "$$MakeNewSignature : " $MakeNewSignature
? "$$MachineExist :" $MachineExist
sleep 0.5
; Has something changed, or does the machine exist in the file?
if $MakeNewSignature <> "yes" and $MachineExist = "yes" ; Nothing has changed, just write info to the log-file
? "Informasjon fra fil er lik informasjon i AD, og " + @wksta + " er det laget signatur for tidligere; ingenting gjøres.."
sleep 0.5
if open (5, "$Log\OutlookSignatur.txt",5) = 0
$Tekst = left (left ( "@YEAR" + "-" + "@MONTHNO" + "-" +"@MDAYNO" + "-" + " ",11) + $klokkeslett + " ---> " + left(@wksta + " " + left(%clientname% + " ",6) + " " + @userid + " ",20) + " - " + left(@fullname + " ",29) + " ",75)
if $LagetNySignatur <> "yes"
writeline (5, $Tekst + "Informasjon er som før, igenting gjøres (" + $StrTitle + ")" + @CRLF)
endif
EndIf
Close (5)
sleep 0.5
cls
return
else ; File-content is different from AD; generate new signature
;debug on
? "Ny signatur må opprettes.."
sleep 0.5
if $MachineExist <> "yes" ; Only machine has changed; write the name of the machine in the users control-file
if open (9, "$Log\OutlookSignature\@userid.txt",5) = 0
writeline (9,@wksta + @CRLF)
close(9)
endif
$x = MakeNewSignature() ; Call the function to generate signature
return
endif
;Something else than the machine has changed: delete existing file and write info from AD in new file
del "$Log\OutlookSignature\@userid.txt" ;
if open (9, "$Log\OutlookSignature\@userid.txt",5) = 0
writeline (9,$strName + @CRLF)
writeline (9, $strTitle + @CRLF)
writeline (9, $strMail + @CRLF)
writeline (9, $strDepartment + @CRLF)
writeline (9, $strCompany + @CRLF)
writeline (9, $strPhone + @CRLF)
writeline (9, $strMobile + @CRLF)
writeline (9, $strWeb + @CRLF)
writeline (9, "----------" + @CRLF)
writeline (9, "Signatur er opprettet på følgende maskiner:" + @CRLF)
writeline (9,@wksta + @CRLF)
close(9)
endif
if $LagetNySignatur = "yes" ; Check if signature has already has been made (can happen if terminalserver-check file has been deleted). Routine to prevent signature to happen twice
return
EndIf
$x = MakeNewSignature() ; Call the function to generate signature
return
Endif
Endif
else ; File doesn't exist. New signature must be generated
? "Ny signatur må opprettes"
sleep 0.5
if exist ("$Log\OutlookSignature\@userid.txt")
del "$Log\OutlookSignature\@userid.txt"
endif
if open (9, "$Log\OutlookSignature\@userid.txt",5) = 0
writeline (9,$strName + @CRLF)
writeline (9, $strTitle + @CRLF)
writeline (9, $strMail + @CRLF)
writeline (9, $strDepartment + @CRLF)
writeline (9, $strCompany + @CRLF)
writeline (9, $strPhone + @CRLF)
writeline (9, $strMobile + @CRLF)
writeline (9, $strWeb + @CRLF)
writeline (9, "----------" + @CRLF)
writeline (9, "Signatur er opprettet på følgende maskiner:" + @CRLF)
writeline (9,@wksta + @CRLF)
close(9)
endif
if $LagetNySignatur = "yes"
return
EndIf
$x = MakeNewSignature()
return
endif
Here's an extraction of one of the file's to compare to:
Users name
Users job-title
username@company.com
Department
11111111
99999999
http://www.company.com
----------
Signature is generated on the following machines:
PC100
11111111 - Office number 99999999 - Moible number
Then the function is being defined. The script is being called from another mainscript, so the reference to a log file will be wrong, possible some other things too.
Hope some of you smart guys (once again) can help me out
_________________________
I was placed on earth to do a job. Right now I have so much to do, I will never die..
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|