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