Hi all,

Having "borrowed" this script and modified, it works fine by itself.
I want to use this as part of a loop to create groups and populate
from a file with format group|user


' SimpleGroup.vbs
' Sample VBScript to create a Global Security Group
' Author Guy Thomas http://computerperformance.co.uk/
' Version 2.4 - May 2005
' ----------------------------------------------------------'

Dim strOU, strGroup, strDNSDomain
Dim objOU, objGroup, objUser

' Check - Make sure you have the OU referenced by strOU
strOU = "OU=Newport,"
strNewGp = "Coal Porters1"
strNewGpLong = "CN=" & strNewGp

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

' Create new Group
Set objOU = GetObject("LDAP://" & strOU & strDNSDomain )
Set objGroup = objOU.Create("Group",strNewGpLong)
objGroup.Put "sAMAccountName", strNewGp
objGroup.setInfo

Wscript.Quit

' End of Simple Group VBScript.


So if I have a group that already exists, it dies. How can I check
for the existence of a group before objGroup.setInfo?

Re: Check if group exists before creating it by Jeremy

Jeremy
Tue May 15 04:57:44 CDT 2007

You need to capture the error and handle it. An unhandled error leads to
the script terminating. The laziest way, but often the most effective for
administrative scripts, is to stick an On Error Resume Next command at the
top of your script. It basically just says, do what I say and if it fails,
pick yourself up and carry on. I've inserted it inline below.


<bakins@gmail.com> wrote in message
news:1179165719.110010.226890@l77g2000hsb.googlegroups.com...
> Hi all,
>
> Having "borrowed" this script and modified, it works fine by itself.
> I want to use this as part of a loop to create groups and populate
> from a file with format group|user
>
>
> ' SimpleGroup.vbs
> ' Sample VBScript to create a Global Security Group
> ' Author Guy Thomas http://computerperformance.co.uk/
> ' Version 2.4 - May 2005
> ' ----------------------------------------------------------'
> On Error Resume Next
> Dim strOU, strGroup, strDNSDomain
> Dim objOU, objGroup, objUser
>
> ' Check - Make sure you have the OU referenced by strOU
> strOU = "OU=Newport,"
> strNewGp = "Coal Porters1"
> strNewGpLong = "CN=" & strNewGp
>
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("DefaultNamingContext")
>
> ' Create new Group
> Set objOU = GetObject("LDAP://" & strOU & strDNSDomain )
> Set objGroup = objOU.Create("Group",strNewGpLong)
> objGroup.Put "sAMAccountName", strNewGp
> objGroup.setInfo
>
> Wscript.Quit
>
> ' End of Simple Group VBScript.
>
>
> So if I have a group that already exists, it dies. How can I check
> for the existence of a group before objGroup.setInfo?
>