Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > VBscript Help please - creating AD groups

Reply
Thread Tools Display Modes

VBscript Help please - creating AD groups

 
 
Clubsprint
Guest
Posts: n/a

 
      09-17-2008
G'day all
I've hobled a script together from the MS examples but it's not working.
I want to create a list of groups in an OU.
I run the script and it asks for the input and then does nothing.

------start script--------

On Error Resume Next

Dim OrgUnit, GroupName, fso, f, objOU, objGroup

Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000

GroupName = InputBox("Enter the name of the Group Name you wish to create")

Set objOU = GetObject("LDAP://ou=Workstation
Groups,ou=Workstations,dc=int,dc=dept,dc=gov")
Set objGroup = objOU.Create("Group", "cn=ChairmanWS")

objGroup.Put "sAMAccountName", "HRStaff"
objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or _
ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo

------start script--------


what does the part
objGroup.Put "sAMAccountName", "HRStaff"
do? I'm not sure how to change this to make it relevent to my site
I'd really like to create the groups from a list in a text file but I've not
beenn able to work that out

thanks in advance


 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      09-17-2008

"Clubsprint" <> wrote in message
news:gaqbjt$s6b$...
> G'day all
> I've hobled a script together from the MS examples but it's not working.
> I want to create a list of groups in an OU.
> I run the script and it asks for the input and then does nothing.
>
> ------start script--------
>
> On Error Resume Next
>
> Dim OrgUnit, GroupName, fso, f, objOU, objGroup
>
> Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
> Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
>
> GroupName = InputBox("Enter the name of the Group Name you wish to
> create")
>
> Set objOU = GetObject("LDAP://ou=Workstation
> Groups,ou=Workstations,dc=int,dc=dept,dc=gov")
> Set objGroup = objOU.Create("Group", "cn=ChairmanWS")
>
> objGroup.Put "sAMAccountName", "HRStaff"
> objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or _
> ADS_GROUP_TYPE_SECURITY_ENABLED
> objGroup.SetInfo
>
> ------start script--------
>
>
> what does the part
> objGroup.Put "sAMAccountName", "HRStaff"
> do? I'm not sure how to change this to make it relevent to my site
> I'd really like to create the groups from a list in a text file but I've
> not beenn able to work that out
>
> thanks in advance
>


First, remove "On Error Resume Next". There is no need for it here and it
suppresses error messages. This makes troubleshooting nearly impossible.

The statement you refer to assigns the value "HRStaff" to the sAMAccountName
attribute. This attribute must have a value that is unique in the domain.
The statement that creates the group assigns a value to the cn attribute
(Common Name). This value must be unique in the OU.

A likely problem is that you have run the script more than once and an error
was raised when you attempted to create a group with duplicate cn or
sAMAccountName. Notice that you prompt for GroupName, but then never use it.
Perhaps you want to use (watch line wrapping):
==============
Option Explicit
Dim GroupName, objOU, objGroup

Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000

GroupName = InputBox("Enter the name of the Group Name you wish to create")

Set objOU = GetObject("LDAP://ou=Workstation
Groups,ou=Workstations,dc=int,dc=dept,dc=gov")
Set objGroup = objOU.Create("Group", "cn=" & GroupName)

objGroup.Put "sAMAccountName", GroupName
objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or _
ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo
========
I added "Option Explicit" so you must declare all variables (in Dim
statements). This helps troubleshooting.

If you are creating groups from a list you can read names from a text file
using the FileSystemObject, then in the loop where you read each line of the
file (using the ReadLine method), create a group with each name (I would
check and skip blank lines, which are common in text files).

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
Clubsprint
Guest
Posts: n/a

 
      09-18-2008
"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:...
>> "Clubsprint" <> wrote in message
>> news:gaqbjt$s6b$...
> > G'day all
> > I've hobled a script together from the MS examples but it's not working.
> > I want to create a list of groups in an OU.
> > I run the script and it asks for the input and then does nothing.
> >
> > ------start script--------

SNIP
>
> First, remove "On Error Resume Next". There is no need for it here and it

Thanks Richard
You were much help I spent half a day finding how to use the FSO and
readline
method you mentioned. It worked finally. Of course I could have done it
manually
but why use a shovel when you can have so much more fun learning how to
drive
a front end loader.
I've included the script for anyone that's interested. Now to populate the
groups. haha.
Mark
Aus
-------------------start script------------------------
Option Explicit
Dim OrgUnit, GroupName, fso, f, objOU, objGroup
DIM sFile, oFSO, sText, oFile
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
Set oFSO = CreateObject("Scripting.FileSystemObject")
sFile = "c:\groups\groupws.txt"
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, 1)
Do While Not oFile.AtEndOfStream
GroupName = oFile.ReadLine
If Trim(GroupName) <> "" Then
Set objOU = GetObject("LDAP://ou=Workstation
Groups,ou=Workstations,dc=int,dc=dept,dc=gov")
Set objGroup = objOU.Create("Group", "cn="& GroupName)
objGroup.Put "sAMAccountName", GroupName
objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or _
ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo
End If
Loop
oFile.Close
Else
WScript.Echo "c:\groups\groupws.txt does not exist."
End If
-------------------end script------------------------






 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      09-18-2008

"Clubsprint" <> wrote in message
news:gaspp6$ea5$...
> "Richard Mueller [MVP]" <rlmueller-> wrote in
> message news:...
>>> "Clubsprint" <> wrote in message
>>> news:gaqbjt$s6b$...
>> > G'day all
>> > I've hobled a script together from the MS examples but it's not
>> > working.
>> > I want to create a list of groups in an OU.
>> > I run the script and it asks for the input and then does nothing.
>> >
>> > ------start script--------

> SNIP
>>
>> First, remove "On Error Resume Next". There is no need for it here and it

> Thanks Richard
> You were much help I spent half a day finding how to use the FSO and
> readline
> method you mentioned. It worked finally. Of course I could have done it
> manually
> but why use a shovel when you can have so much more fun learning how to
> drive
> a front end loader.
> I've included the script for anyone that's interested. Now to populate the
> groups. haha.
> Mark
> Aus
> -------------------start script------------------------
> Option Explicit
> Dim OrgUnit, GroupName, fso, f, objOU, objGroup
> DIM sFile, oFSO, sText, oFile
> Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
> Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> sFile = "c:\groups\groupws.txt"
> If oFSO.FileExists(sFile) Then
> Set oFile = oFSO.OpenTextFile(sFile, 1)
> Do While Not oFile.AtEndOfStream
> GroupName = oFile.ReadLine
> If Trim(GroupName) <> "" Then
> Set objOU = GetObject("LDAP://ou=Workstation
> Groups,ou=Workstations,dc=int,dc=dept,dc=gov")
> Set objGroup = objOU.Create("Group", "cn="& GroupName)
> objGroup.Put "sAMAccountName", GroupName
> objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or _
> ADS_GROUP_TYPE_SECURITY_ENABLED
> objGroup.SetInfo
> End If
> Loop
> oFile.Close
> Else
> WScript.Echo "c:\groups\groupws.txt does not exist."
> End If
> -------------------end script------------------------
>


You got it, looks good. The only suggestion I have is bind the objOU object
outside the Do While loop. It never changes, so there is no need to
repeatedly bind to the same object (binding to remote objects, as in AD, is
the slowest operation in most scripts). Minor point.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
Clubsprint
Guest
Posts: n/a

 
      09-23-2008
Cheers, thanks gor your help.
Mark'

"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:O%...
>
> "Clubsprint" <> wrote in message
> news:gaspp6$ea5$...
>> "Richard Mueller [MVP]" <rlmueller-> wrote in
>> message news:...
>>>> "Clubsprint" <> wrote in message
>>>> news:gaqbjt$s6b$...
>>> > G'day all
>>> > I've hobled a script together from the MS examples but it's not
>>> > working.
>>> > I want to create a list of groups in an OU.
>>> > I run the script and it asks for the input and then does nothing.
>>> >
>>> > ------start script--------

>> SNIP
>>>
>>> First, remove "On Error Resume Next". There is no need for it here and
>>> it

>> Thanks Richard
>> You were much help I spent half a day finding how to use the FSO and
>> readline
>> method you mentioned. It worked finally. Of course I could have done it
>> manually
>> but why use a shovel when you can have so much more fun learning how to
>> drive
>> a front end loader.
>> I've included the script for anyone that's interested. Now to populate
>> the groups. haha.
>> Mark
>> Aus
>> -------------------start script------------------------
>> Option Explicit
>> Dim OrgUnit, GroupName, fso, f, objOU, objGroup
>> DIM sFile, oFSO, sText, oFile
>> Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
>> Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
>> Set oFSO = CreateObject("Scripting.FileSystemObject")
>> sFile = "c:\groups\groupws.txt"
>> If oFSO.FileExists(sFile) Then
>> Set oFile = oFSO.OpenTextFile(sFile, 1)
>> Do While Not oFile.AtEndOfStream
>> GroupName = oFile.ReadLine
>> If Trim(GroupName) <> "" Then
>> Set objOU = GetObject("LDAP://ou=Workstation
>> Groups,ou=Workstations,dc=int,dc=dept,dc=gov")
>> Set objGroup = objOU.Create("Group", "cn="& GroupName)
>> objGroup.Put "sAMAccountName", GroupName
>> objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or _
>> ADS_GROUP_TYPE_SECURITY_ENABLED
>> objGroup.SetInfo
>> End If
>> Loop
>> oFile.Close
>> Else
>> WScript.Echo "c:\groups\groupws.txt does not exist."
>> End If
>> -------------------end script------------------------
>>

>
> You got it, looks good. The only suggestion I have is bind the objOU
> object outside the Do While loop. It never changes, so there is no need to
> repeatedly bind to the same object (binding to remote objects, as in AD,
> is the slowest operation in most scripts). Minor point.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a hyperlink in Excel ss using vbscript jbruns Scripting 4 02-27-2006 06:06 PM
Adding Groups on the basis of text in a VBScript verge Scripting 6 11-15-2005 01:41 AM
Looking for example of creating a SQL table using wsh/vbscript EBrander Scripting 3 04-21-2005 11:45 PM
RE: Export Active Directory Groups via vbscript ptwilliams Active Directory 0 04-19-2005 04:21 PM
vbScript for creating Excel charts? Troy Bruder Scripting 4 07-09-2004 01:18 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59