preload

Active Directory Scripting – a little trick for fail-safe automation

Posted by Albert Gareev on Apr 13, 2010 | Categories: Back-endSource code

Reference page: Active Directory – Sample Scripts (Excel/VBA) 

While processing User Account put the following code in the beginning of operations to disable it.


'Disable user account.
objUser.AccountDisabled = True

'Save info
On Error Resume Next
objUser.SetInfo
boolRC = (Err.Number <> 0)
On Error GoTo 0

If boolRC Then
'recovery code

End If

And enable it back once you’re successfully done.


'Enable user account
objUser.AccountDisabled = False

'Save info
On Error Resume Next
objUser.SetInfo
boolRC = (Err.Number <> 0)
On Error GoTo 0

If boolRC Then
'recovery code

End If

This way,  in case of an unhandled exception that breaks execution of a script, any User Account that wasn’t properly processed will remain disabled and easily noticeable.


  • 2 responses to "Active Directory Scripting – a little trick for fail-safe automation"

  • Uncor
    24th April 2010 at 3:57

    Sure this testers are paranoid! :)

    [Albert’s Reply. We might seem paranoid at times but we’re not pessimistic!]

  • Heather
    22nd October 2010 at 10:14

    Great narrative, sweet and simple. Thanks!

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.