#74164 - 2003-03-24 10:17 PM
Can anyone help me with this code?
|
DJ Ballistic
Starting to like KiXtart
Registered: 2003-02-21
Posts: 185
|
Awhile back someone created this utility if you will that will query the active directory of my domain and automatically assign logon.bat to each user in a particular OU. It works perfectly, however, in case something goes sour after we deploy this is there a way to change something in the code and run it again on that OU to remove the logon.bat entry under profile for the user.
Here is the code:
code:
Break ON $rc=SetOption('WrapAtEOL','ON')
; uncomment the next line to step through the code ; Debug ON ; Example of LDAP call. GetObject("LDAP://ou=Users,ou=YourBusinessUnit,dc=YourCompany,dc=com") ; You need to know your LDAP connection. You can maybe find it by checking the propery details on the OU for your users. $target = GetObject("LDAP://OU=Test,OU=AdminBldg,DC=sussexcounty,DC=net") ? 'Error = '+@ERROR+' - '+@SERROR $loginscript="Logon.bat" For Each $user in $target ? 'checking user: '+$user.name $script = $user.loginscript $loginscripterror = @error ? "Logon script error: @error - @serror" ? 'assigned login script: '+$script If $Script <> $loginscript OR $loginscripterror ? "Current Script for " +$user.name " is: " +$script+ " Should be: " +$loginscript $user.loginscript=$loginscript ; Remove the semi-colon at the front of this line to enable actually resetting the logon bat. ? 'Error = '+@ERROR+' - '+@SERROR $user.SetInfo ; Remove the semi-colon at the front of this line to enable actually resetting the logon bat. ? 'Error = '+@ERROR+' - '+@SERROR ? "Changed current Script for " +$user.name " to: " +$user.loginscript EndIf Next ? 'If no user was displayed, then no user was retrieved from the OU'
Sleep 2
|
|
Top
|
|
|
|
#74166 - 2003-03-24 11:29 PM
Re: Can anyone help me with this code?
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Just out of curiousity, I ran the script to check this out.. If there is an error, it never gets reset..
code:
BREAK ON $rc=SetOption('WrapAtEOL','ON')
; uncomment the next line to step through the code ; Debug ON ; Example of LDAP call. GetObject("LDAP://ou=Users,ou=YourBusinessUnit,dc=YourCompany,dc=com") ; You need to know your LDAP connection. You can maybe find it by checking the propery details on the OU for your users. $target = GetObject("LDAP://OU=Test,OU=AdminBldg,DC=sussexcounty,DC=net") ? 'Error = '+@error+' - '+@serror $loginscript="ntlogon.bat" FOR EACH $user IN $target ? 'checking user: '+$user.name $script = $user.loginscript ? 'assigned login script: '+$script IF @error <> O $loginscripterror = @error ? "Logon script error: @error - @serror" IF $script <> $loginscript OR $loginscripterror ? "Current Script for " +$user.name " is: " +$script+ " Should be: " +$loginscript ;;$user.loginscript=$loginscript ; Remove the semi-colon at the front of this line to enable actually resetting the logon bat. ;;? 'Error = '+@error+' - '+@serror ;;$user.SetInfo ; Remove the semi-colon at the front of this line to enable actually resetting the logon bat. ;;? 'Error = '+@error+' - '+@serror ;;? "Changed current Script for " +$user.name " to: " +$user.loginscript ENDIF $loginscripterror = 0 SLEEP 2 ENDIF NEXT
HTH,
Kent [ 24. March 2003, 23:36: Message edited by: kdyer ]
|
|
Top
|
|
|
|
#74168 - 2003-03-24 11:41 PM
Re: Can anyone help me with this code?
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Doc,
Understood..
It was just something that I wanted to try as I may have a need for this coming up soon.
Kent
|
|
Top
|
|
|
|
#74169 - 2003-03-25 08:02 PM
Re: Can anyone help me with this code?
|
DJ Ballistic
Starting to like KiXtart
Registered: 2003-02-21
Posts: 185
|
I can't find the code now that has it reset. I tried assigning a blank logon script and it won't take it.
|
|
Top
|
|
|
|
#74170 - 2003-03-25 08:07 PM
Re: Can anyone help me with this code?
|
DJ Ballistic
Starting to like KiXtart
Registered: 2003-02-21
Posts: 185
|
Oh yes got the code to take the logon.bat assignment back out by adding this after the ="" That removed the script assignment. I still cannot find the thread where there was code posted about if there were errors to reset. I thought I had all of the code that was posted by Howard on this issue.
|
|
Top
|
|
|
|
#74172 - 2003-03-25 08:27 PM
Re: Can anyone help me with this code?
|
DJ Ballistic
Starting to like KiXtart
Registered: 2003-02-21
Posts: 185
|
OK I have been through the old posts and what NTDOC posted is the same that I have. I don't see anywhere that there is a place to have it reset if an error occurs. Here is the code from NTDOC's post.
code:
BREAK ON ; Example of LDAP call. GetObject("LDAP://ou=Users,ou=YourBusinessUnit,dc=YourCompany,dc=com") ; You need to know your LDAP connection. You can maybe find it by checking the propery details on the OU for your users. $target = GetObject("LDAP://your LDAP details") $loginscript="yourlogon.bat" for each $user in $target if $user.loginscript <> "$loginscript" ? "Current Script for " +$user.name " is: " +$user.loginscript+ " Should be: " +$loginscript ; $user.loginscript=$loginscript ; Remove the semi-colon at the front of this line to enable actually resetting the logon bat. ; $user.SetInfo ; Remove the semi-colon at the front of this line to enable actually resetting the logon bat. endif next
|
|
Top
|
|
|
|
#74174 - 2003-03-25 08:32 PM
Re: Can anyone help me with this code?
|
DJ Ballistic
Starting to like KiXtart
Registered: 2003-02-21
Posts: 185
|
Actually at any rate i figured out how to make the result null for the logon script and it works now.
|
|
Top
|
|
|
|
#74176 - 2003-03-26 06:52 AM
Re: Can anyone help me with this code?
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
I wrote the original code myself a long time ago to work on our system. Howard noticed that it might be possible for an error to occur which might prevent a proper update.
Apparently you did not understand DJ as Jens explained to you already in the first reply to set it to a blank entry. KiXtart does this by using either '' or "" If you were not sure what Jens was talking about, you should have posted and asked more specifically what he meant.
Howard modified my code a little. It is posted here. http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=2;t=004215;p=5
Essentially the code is:
Break ON ; uncomment the next line to step through the code ; Debug ON $target = GetObject("LDAP://OU=Test,OU=Information Systems,OU=AdminBldg,DC=sussexcounty,DC=net") ? 'Error = '+@ERROR+' - '+@SERROR $loginscript="logon.bat" For Each $user in $target ? 'checking user: '+$user.name $script = $user.loginscript ? 'Logon script error: @error - @serror' ? 'assigned login script: '+$script If $Script <> $loginscript ? "Current Script for " +$user.name " is: " +$script+ " Should be: " +$loginscript $user.loginscript=$loginscript ? 'Error = '+@ERROR+' - '+@SERROR $user.SetInfo ? 'Error = '+@ERROR+' - '+@SERROR ? "Changed current Script for " +$user.name " to: " +$user.loginscript EndIf Next ? 'If no user was displayed, then no user was retrieved from the OU'
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2375 anonymous users online.
|
|
|