License Group WMI/ADSI script or Reskit Utility

A

AVTechs

Does anyone know if there is a resource kit utility that allows you to
add/remove users from a "license group" at the command line in Windows
2000/2003 server?

If not, has anyone seen any WMI/ADSI .vbs scripts that can do this?

Even a link to the technet page that shows syntax for doing this would be
great.

Thanks,
 
R

Richard Mueller

AVTechs said:
Does anyone know if there is a resource kit utility that allows you to
add/remove users from a "license group" at the command line in Windows
2000/2003 server?

If not, has anyone seen any WMI/ADSI .vbs scripts that can do this?

Even a link to the technet page that shows syntax for doing this would be
great.

Hi,

Assuming a "license group" is like any Active Directory group, you can use
the net group command at the command prompt of a Domain Controller. The
syntax would be:

net group domain_group_name domain_user_name /add

You use the NetBIOS (NT) names of the objects. You could code a batch file
and pass the NT names to it.

In VBScript you bind using the Distinguished Names of the objects. You can
test membership with the IsMember method and add members with the Add method
of the group object, specifying the AdsPath of the prospective member. For
example:
=============
Set objGroup = GetObject("LDAP://cn=TestGroup,ou=Sales,dc=MyDomain,dc=com")
Set objMember = GetObject("LDAP://cn=JUser,ou=East,dc=MyDomain,dc=com")
If Not objGroup.IsMember(objMember.AdsPath) Then
objGroup.Add(objMember.AdsPath)
End If
=============

Distinguished Names may not be to your liking. A VBScript program that
accepts NT names of users (the "pre-Windows 2000 logon name") would require
using the NameTranslate object to convert to Distinguished Names. Such a
program follows:
=====================
' Program to add users to a specified group.
' Users are specified by NT name (pre-Windows 2000 logon name).

Option Explicit
Dim objGroup, strNTName, objMember
Dim objTrans, objRootDSE, strDNSDomain, strNetBIOSDomain
Dim strDN, strGroupDN

' Constants for NameTranslate.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Hard code the Distinguished Name of the group.
strGroupDN = "cn=TestGroup,ou=Sales,dc=MyDomain,dc=com"

' Bind to the group object.
Set objGroup = GetObject("LDAP://" & strGroupDN)

' Check for argument, NT name of prospective member.
If (Wscript.Arguments.Count <> 1) Then
Wscript.Echo "Required argument (NT name of user) missing."
Wscript.Quit
End If

' Retrieve NT name of prospective member.
strNTName = Wscript.Arguments(0)

' Determine DNS name of domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use NameTranslate to convert DNS name of domain to NetBIOS name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
' The NetBIOS name of the domain has a trailing backslash.
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)

' Convert NT name of member to Distinguished Name.
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & strNTName
strDN = objTrans.Get(ADS_NAME_TYPE_1779)

' Bind to the member object.
Set objMember = GetObject("LDAP://" & strDN)

' Test for membership.
If Not objGroup.IsMember(objMember.AdsPath) Then
objGroup.Add(objMember.AdsPath)
Wscript.Echo strNTName & " added to group."
Else
Wscript.Echo strNTName & " is already a member of group."
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top