Re: script interaction
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 10 Feb 2006 20:20:54 -0600
Hi,
If I understand, you want to prompt for a "base" group name, like "DL
Security Group" and have the script create groups "DL Security Group 1"
through "DL Security Group 6". That can certainly be done. Is the sequence 1
through 6 fixed? Are the groups always to be created in the same
OU/Container? And, how does the script know what to use for the
sAMAccountName, especially since the value must be unique in the domain.
You can use the InputBox function to prompt for a name. If I assume you
always create 6 groups for each "base" group name and always in the same OU,
and further that the sAMAccountName should be a shortened version of the cn,
the script could be similar to:
====================
Option Explicit
Dim strBaseName, objOU, intCount, objGroup, strNTName, strCN
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
' Prompt for base group name.
strBaseName = InputBox("Enter the base group name.")
' Quit if user enters nothing or cancels.
If (Trim(strBaseName) = "") Then
Wscript.Quit
End If
' Bind to OU/Container.
Set objOU = GetObject("LDAP://cn=Computers,dc=NA,dc=fabrikam,dc=com")
' Create 6 groups from the base group name.
For intCount = 1 To 6
' Construct the Common Name from the base name and intCount.
strCN = strBaseName & " " & CStr(intCount)
' Create group with the Common Name in the OU/Container.
Set objGroup = objOU.Create("group", "cn=" & strCN)
' The sAMAccountName should not have spaces, dashes, or commas.
strNTName = Replace(strCN, " ", "")
strNTName = Replace(strNTName, "-", "")
strNTName = Replace(strNTName, ",", "")
' sAMAccountName is limited to 20 characters.
' To help ensure uniqueness, the last character should be retained.
If (Len(strNTName > 20) Then
strNTName = Left(strNTName, 19) & Right(strNTName, 1)
End If
' Assign sAMAccountName and groupType.
objGroup.Put "sAMAccountName", strNTName
objGroup.Put "groupType", ADS_GROUP_TYPE_LOCAL_GROUP Or _
ADS_GROUP_TYPE_SECURITY_ENABLED
' Save changes.
objGroup.SetInfo
Next
====================
I guess the point is that you can concatenate variable names into strings
and assign these as values for attributes in any way you wish. You just have
to meet rules about uniqueness in the domain or container, allowed
characters, etc. For example, values for sAMAccountName cannot have any of
the following characters:
"\/[]:;|=,+*?<>
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
"m0rk" <no@xxxxxxxxxx> wrote in message
news:MPG.1e57390e643de720989781@xxxxxxxxxxxxxxxxxxxx
I am starting this weekend to look at creating a script to create
several AD security groups for a requested variable. If I enter "DL
Security Group" I want it to create "DL Security Group 1" through to "DL
Security Group 6"
I have never scripted before.
How do I get the script to pop up and request me to enter the variable -
basically, the name of the of the security group I want to create - I
dont want to hard code it, I want to enter a different one manually each
time I run the script.
I have the following example script:-
;Description - Creates a domain local Active Directory security group
named DB-Servers.
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
Set objOU = GetObject("LDAP://cn=Computers,dc=NA,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=DB-Servers")
objGroup.Put "sAMAccountName", "DBServers"
objGroup.Put "groupType", ADS_GROUP_TYPE_LOCAL_GROUP Or _
ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo
.
- Follow-Ups:
- Re: script interaction
- From: m0rk
- Re: script interaction
- Prev by Date: Re: Create a .NET oject from vbs
- Next by Date: Browsering for Files
- Previous by thread: Create a .NET oject from vbs
- Next by thread: Re: script interaction
- Index(es):
Relevant Pages
|
Loading