Recipe 15.7. Setting a Domain User's Account OptionsProblemYou want to view or update the userAccountControl attribute for a domain user. This attribute controls various account options, such as when the user must change his password at next logon and whether the account is disabled. SolutionUsing a graphical user interface
Using a command-line interfaceThe dsmod user command has several options for setting various userAccountControl flags as shown in Table 15-1. Each switch accepts yes or no as a parameter to either enable or disable the setting. Using VBScript' This code enables or disables a bit value in the userAccountControl attr. ' ------ SCRIPT CONFIGURATION ------ strUserDN = "<UserDN>" ' e.g. cn=rallen,ou=Sales,dc=rallencorp,dc=com intBit = <BitValue> ' e.g. 65536 boolEnable = <TrueOrFalse> ' e.g. TRUE ' ------ END CONFIGURATION --------- strAttr = "userAccountControl" set objUser = GetObject("LDAP://" & strUserDN) intBitsOrig = objUser.Get(strAttr) intBitsCalc = CalcBit(intBitsOrig, intBit, boolEnable) if intBitsOrig <> intBitsCalc then objUser.Put strAttr, intBitsCalc objUser.SetInfo WScript.Echo "Changed " & strAttr & " from " & _ intBitsOrig & " to " & intBitsCalc else WScript.Echo "Did not need to change " & strAttr & " (" & _ intBitsOrig & ")" end if Function CalcBit(intValue, intBit, boolEnable) CalcBit = intValue if boolEnable = TRUE then CalcBit = intValue Or intBit else if intValue And intBit then CalcBit = intValue Xor intBit end if end if End FunctionDiscussionThe userAccountControl attribute on user (and computer) accounts could be considered the kitchen sink of miscellaneous and sometimes completely unrelated user account properties. If you have to do much creating and managing user accounts, you'll need to become intimately familiar with this attribute. The userAccountControl attribute is a bit flag, which means you have to take a couple extra steps to search against it or modify it. For more on searching and modifying a bit flag attribute, see Recipes 4.10 and 4.13 in Active Directory Cookbook. The dsmod user command can be used to modify a subset of userAccountControl properties as shown in Table 15-1. Table 15-2 contains the complete list userAccountControl properties as defined in the ADS_USER_FLAG_ENUM enumeration.
See AlsoGo to MSDN (http://msdn.microsoft.com) and search for "ADS_USER_FLAG_ENUM enumeration" |