<rss version="2.0"><channel><title>TRCB.com RSS Feed</title><description>Creating a Local Group: To create a local group, we are going to use two IADs methods: "Create" and "SetInfo." When we call the Create method, it is actually the method of the group parent object-in this case, the object representing the computer. The syntax is shown in the following example: Set objGroup = objComputer.Create("group", "GroupName")</description><link>http://www.trcb.com/</link><language>en-Us</language><ttl>60</ttl><lastBuildDate>Fri, 10 Feb 2012 04:43:32 EST</lastBuildDate><copyright>Copyright 2012 Jada  Brock-Soldavini, TRCB.com All Right Reserved</copyright><item><title>Windows Server 2003 Creating a Local Group</title><link>http://www.trcb.com/computers-and-technology/windows-server-2003/windows-server-2003-creating-a-local-group-2326.htm</link><description>&lt;p&gt;&lt;strong&gt;Creating a Local Group:&amp;nbsp;&lt;/strong&gt;To create a local group, we are going to use two IADs methods: "Create" and "SetInfo."&amp;nbsp;When we call the Create method, it is actually the method of the group parent object-in this case, the object representing the computer.  The syntax is shown in the following example: &amp;nbsp;Set objGroup = objComputer.Create("group", "GroupName")&lt;/p&gt;&lt;p&gt;The Create GroupName script :As you can see, the Create method takes two arguments: the type of object to create ("group"), and the name for the new object ("GroupName"). &lt;br /&gt;The SetInfo method, on the other hand, is the method of the newly created group.  It must be called to commit the change.&lt;/p&gt;&lt;p&gt;objGroup.SetInfo&amp;nbsp;&amp;nbsp;The script used to SetInfo.&lt;/p&gt;&lt;p&gt;We are going to take a working piece of code-a Windows Script command line utility-to illustrate how a local group can be created on a machine named "TRPublicComputer". This code requires two arguments at runtime: the name of the group to create, and the new group description.&lt;/p&gt;&lt;p&gt;The presumption is made in this sample that TRPublicComputer is the only computer on which local groups are being created.  With a little modification, a third argument could be passed using the declared variable strADspath, a binding string (such as WinNT://computername) of the object to which you want to add the group.&lt;/p&gt;&lt;p&gt;We will call the script "CreateLocalGroup.vbs".  In this case, we are going to create a group called "Visitors" with a description of "Area 51."  To call the script, at the command line, the following syntax would be used:&amp;nbsp;wscript CreateLocalGroup.vbs "Visitors" "Area 51"&lt;br /&gt;Script : Creating a local group called Visitors with a description of Area 51.&lt;/p&gt;&lt;p&gt;Note that while quotes are not necessary for the first parameter, Visitors, they are for the second parameter, Area 51, because of the space.  It is always good practice to use quotation marks, even when not necessary.&lt;/p&gt;&lt;p&gt;Prior to running the script, the Groups on the machine appeared as in the following illustration:&lt;/p&gt;&lt;p&gt;Pre-existing local groups on TRPublicComputer.&lt;br /&gt;To start declare the variables that will be needed in the script.  The first three variables are string variables.  &lt;br /&gt;a.strADsPath" is a set variable pointing to the computer "TRPublicComputer".  &lt;br /&gt;b.The other two string variables "strGroupName" and "strDescription" are set to the arguments stated at runtime.  &lt;br /&gt;c.The second set of variables are object variables.  The first "objTarget" will contain the object to which you wish to add the group (TRPublicComputer) and the second "objNewGroup" will contain the new group with the description property set.&lt;br /&gt;The script will look as the one does in Script  &lt;br /&gt;Dim strADsPath&lt;br /&gt;Dim strGroupName&lt;br /&gt;Dim strDescription&amp;nbsp;Dim objTarget &lt;br /&gt;Dim objNewGroup&lt;br /&gt;Script : The script used  to declare string variables. &lt;br /&gt;On Error Resume Next has been used to trap expected errors in the input arguments.  As we will be passing two arguments, the group name and group description, error trapping has been coded to ensure that both arguments, and no more, have been passed.  If the correct information has not been passed at runtime, messages will be passed to the administrator.  &lt;br /&gt; &lt;br /&gt;&lt;strong&gt;The error resume script is shown in Script:&lt;/strong&gt;&lt;br /&gt;On Error Resume Next&lt;br /&gt;If WScript.Arguments.Count &amp;lt;&gt; 2 Then&lt;br /&gt; WScript.Echo "Wrong number of arguments."&lt;br /&gt; WScript.Echo "Syntax:  CreateLocalGroup.vbs  "&lt;br /&gt; WScript.Echo "name         Name for the new group."&lt;br /&gt; WScript.Echo "description  Description of the new Group."&lt;br /&gt; WScript.Quit(1)&lt;br /&gt;End If&lt;br /&gt;Script &amp;nbsp;The script to resume to the next script On Error.&lt;br /&gt;Values are then assigned to the string variables previously declared as shown in Script  &lt;br /&gt;strADsPath = "WinNT://TRPublicComputer"&lt;br /&gt;strGroupName = WScript.Arguments(0)&lt;br /&gt;strDescription = WScript.Arguments(1)&lt;br /&gt;Script : Assigned Values to the string values previously declared.&lt;br /&gt;We then bind to the computer object.  The error subroutine "AdsiErr()" is outlined later in the code Script 2.8 shows this.&lt;br /&gt;Set objTarget = GetObject(strADsPath)&lt;br /&gt;If Err Then AdsiErr()&lt;/p&gt;&lt;p&gt;Script : The error subroutine "AdsiErr".&lt;br /&gt;The user object is now created and SetInfo is used to commit the change, the new group, to the directory shown in Script .&lt;br /&gt;Set objNewGroup = objTarget.Create("group", strGroupName)&lt;br /&gt;objNewGroup.SetInfo&lt;br /&gt;If Err Then AdsiErr()&lt;br /&gt;&amp;nbsp;The SetInfo command commits the change for the user object.&lt;br /&gt;The description property is set for the new group, and once again SetInfo is called to commit the description to the directory shown below in Script.&lt;br /&gt;objNewGroup.Description = strDescription&lt;br /&gt;objNewGroup.SetInfo&lt;br /&gt;If Err Then AdsiErr()&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Setting the Description Property for the new group:&lt;/strong&gt;&lt;br /&gt;This code will notify the user that the group has been successfully created, and display the name and description of the new group.  &lt;br /&gt;Script &amp;nbsp;shows the GetInfo command that is called to ensure that the actual values of Name and Description exist.&lt;br /&gt;objNewGroup.GetInfo&lt;br /&gt;strGroupName = objNewGroup.Name&lt;br /&gt;strDescription = objNewGroup.Description&lt;br /&gt;WScript.Echo "New group " &amp;amp; strGroupName &amp;amp; " created."&lt;br /&gt;WScript.Echo "Description: " &amp;amp; strDescription&lt;br /&gt;Script : The GetInfo command.&lt;/p&gt;&lt;p&gt;The administrator would then be displayed the following message boxes. and &amp;nbsp;Dialog boxes displayed for administrators.&lt;br /&gt;The last part of the script is the AdsiErr() subroutine.  It handles two errors that might occur while creating the new group-if a group of the specified name already exists or if the specified group name is invalid.  &lt;br /&gt; &lt;br /&gt;Any other error is reported as an unexpected error then exits the AdsiErr() subroutine is shown in Script .&lt;br /&gt;Sub AdsiErr()&lt;br /&gt; Dim scriptoutput&lt;br /&gt; Dim errornumber&lt;br /&gt; &amp;lsquo;if the group name exists    &lt;br /&gt;If Err.Number = &amp;amp;H80070563 Then&lt;br /&gt; scriptoutput = "The group " &amp;amp; strGroupName &amp;amp; " already exists."&lt;br /&gt;&amp;lsquo;if the group name is invalid    &lt;br /&gt;ElseIf Err.Number = &amp;amp;H800A0408 Then&lt;br /&gt; scriptoutput = "The name '" &amp;amp; strGroupName &amp;amp; "' is invalid as a group Name."&amp;lsquo;other error &lt;br /&gt; Else&lt;br /&gt; errornumber = Hex(Err.Number)&lt;br /&gt; scriptoutput = "Unexpected Error " &amp;amp; errornumber &amp;amp; "(" &amp;amp; Err.Number &amp;amp; ")"&lt;br /&gt; End If&lt;br /&gt; WScript.Echo scriptoutput&lt;br /&gt; WScript.Quit(1)&lt;br /&gt; End Sub&lt;br /&gt;The Subroutine AdsiErr.&lt;br /&gt;shows what appears after running this script-the Groups on the computer TRPublicComputer:&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;The output in the console after running the script:&lt;/strong&gt;&lt;br /&gt;Most of the samples below are specific to the task at hand; however, each could be modified to hold arguments that are passed at runtime, rather than the identified group or ADsPath.&lt;br /&gt;Creating a Global Group&lt;br /&gt;The following simple script segment demonstrates how you could modify the script previously described to create a global, rather than a local, groups.  &lt;br /&gt;We are working with two variables:&lt;br /&gt;?objOU, which is the OU in which the group will be contained; and&lt;br /&gt;?objGroup, which is the new group.&lt;br /&gt;We are also using Name Properties to specify the path in the binding string for Active Directory.  A few of the name properties with which you should be familiar are:&lt;br /&gt;?CN - common name&lt;br /&gt;?DC - domain component&lt;br /&gt;?OU - organizational unit.&lt;br /&gt;For example, in the ADsPath in the script sample below, we are using OU to specify that the organizational unit is named "management", and that the domain components are "TotalRecallPress" and "com".  The common name for the group is "visitors".  &lt;br /&gt;Script &amp;nbsp;shows the Set objOU script.&lt;br /&gt;Set objOU = _&lt;br /&gt; GetObject("LDAP://OU=management,dc=totalrecallpublications,dc=com")&lt;br /&gt;Set objGroup = objOU.Create("Group", "cn=visitors")&lt;br /&gt;objGroup.Put "sAMAccountName", "visitors"&lt;br /&gt;objGroup.SetInfo&lt;br /&gt;Script &amp;nbsp;The Set objOU script.&lt;br /&gt;Listing Group Members&lt;br /&gt;Let's say that you need to modify the access permissions of a particular group.  One of the things that must be considered is the effect this will have on each of the members, based on membership in other groups in the domain.  &lt;br /&gt; &lt;br /&gt;Listing the members of a particular group can be easily automated, using the ADsPath and a simple "for" loop as shown in Script .&lt;br /&gt;Set objGroup = GetObject _&lt;br /&gt; ("LDAP://cn=visitors,ou=public,dc=totalrecallpublications,dc=com")&lt;br /&gt;For each objMember in objGroup.Members&lt;br /&gt;Wscript.Echo objMember.Name&lt;br /&gt;Next&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Script to list Group Members.&lt;/strong&gt;&lt;br /&gt;Enumerating Groups and their Membership&lt;br /&gt;It is almost as simple to enumerate all the groups on a specific computer as well as their membership.  The script below demonstrates the way to enumerate the local groups and their membership on a specific computer, TRPublicComputer.  The filter property of the IADsContainer interface was used to specify the Class of group shown in Script .&lt;br /&gt;strComputer = "TRPublicComputer"&lt;br /&gt;Set colGroups = GetObject("WinNT://" &amp;amp; strComputer &amp;amp; "")&lt;br /&gt;colGroups.Filter = Array("group")&lt;br /&gt;For Each objGroup In colGroups&lt;br /&gt; Wscript.Echo objGroup.Name &lt;br /&gt; For Each objUser in objGroup.Members&lt;br /&gt; Wscript.Echo vbTab &amp;amp; objUser.Name&lt;br /&gt; Next&lt;br /&gt;NextScript : Enumerating Groups and their Memberships.&amp;nbsp;&lt;/p&gt;</description><pubDate>Fri, 14 Nov 2008 12:45:40 EST</pubDate><guid>http://www.trcb.com/computers-and-technology/windows-server-2003/windows-server-2003-creating-a-local-group-2326.htm</guid><source url="http://www.trcb.com/rss/article/windows-server-2003-creating-a-local-group-2326.xml">TRCB.com</source><category>Computers and Technology / Windows Server 2003 </category></item></channel></rss>
