Re: script interaction



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


.



Relevant Pages

  • Re: error " constraint violation"
    ... I have rewritten my script. ... assign a value for groupType, the system defaults to create a Global ... but you must assign a value to sAMAccountName before ... : An example from the TechNet Script Center to create a Global security group: ...
    (microsoft.public.scripting.vbscript)
  • Re: Memory output format
    ... You read sAMAccountName and assign the value to variable strName, ... not the computer identified by the variable strComputer. ... "Select Name, sAMAccountName, operatingSystem, description " _ ... I am using your script in the middle of a script pulling wmi info from ...
    (microsoft.public.scripting.wsh)
  • Re: Logon Script to map network drives based on users memberships in security groups
    ... relating the script to what security group my users are in. ... if my user is in the "IT$ Management" security group he ... A VBScript program can map network drives and check group membership. ...
    (microsoft.public.windows.server.scripting)
  • Re: Changing user logon names via script
    ... "sAMAccountName" attribute is the NT logon name. ... MoveHere method to modify it. ... If you plan to adjust the names after the migration, a script can definitely ... values in the intermediate text file or spreadsheet. ...
    (microsoft.public.windows.server.scripting)
  • RE: Add Users to Security Groups
    ... your script should run a loop to scan from col to col n of current row ... as we are passing original user samaccountname from spreadsheet n passing it ... same spreadsheet (intRow, 4). ...
    (microsoft.public.windows.server.scripting)

Loading