The following example demonstrates how to create procedures using the Tcl
proc command. These two procedures create a new Active Directory user and Active Directory group, respectively, but first check to see if that object already exists in Active Directory.
This example uses the Tcl
if commands to determine if the account already exists.
catch takes a Tcl script (in this case, the
select_object command) and returns a
1 if an error (in this case, the account does NOT exist) occurs. Inside the
if command, a non-zero result of the expression causes the body commands (
create_adgroup) to be executed. Otherwise, if
select_object is successful (the account exists) it does not create the new account.
Note: See the
AddUnixUsers script for a similar example that uses the
if commands to determine if a user exists.