Markus_Hahn
(Fresh Scripter)
2006-03-10 04:57 PM
Create a group in Active Directory

I want to create a new group in my Active directory using the following script:

$DomainName=EUROPE.fs.mydomain.com
$ADsPath="LDAP://OU=Groups,OU=DE,DC=europe,DC=FS,DC=mydomain,DC=com"

CreateGroup("GDEUTest","Testgruppe")

Function CreateGroup($GRPName, $description)

$OUObj = GetObject($ADsPath)
$UserObj = $OU.Create("Group","cn=$GRPName")
$UserObj.Put ("description", $description)
$UserObj.Put ("sAMAccountName", $GRPName)
$UserObj.SetInfo

; Objects cleanup
$UserObj = 0
$OUObj = 0

EndFunction


Whenever I run it I get this error:

ERROR : expected ')'!

which shall be in this line:
$UserObj = $OU.Create("Group","cn=$GRPName")

I cannot find the error. Can anyone help ?


Gargoyle
(MM club member)
2006-03-10 05:52 PM
Re: Create a group in Active Directory

Change $UserObj = $OU.Create("Group","cn=$GRPName") to
$UserObj = $OU.Create("Group","cn="+$GRPName)


Markus_Hahn
(Fresh Scripter)
2006-03-10 06:19 PM
Re: Create a group in Active Directory

Already tried that. Unfortunately didn't help.

Gargoyle
(MM club member)
2006-03-10 06:30 PM
Re: Create a group in Active Directory

$OU.Create should that not be $OUObj.Create(...), you do not have $OU defined

Shaun_Hill
(Getting the hang of it)
2006-03-10 07:16 PM
Re: Create a group in Active Directory

Not sure if this helps but you have $GRPName enclosed in string.
$UserObj = $OU.Create("Group", "cn=$GRPName")
This may or may not be the problem


Shaun_Hill
(Getting the hang of it)
2006-03-10 07:32 PM
Re: Create a group in Active Directory

Also try $OUObj = GetObject("LDAP://OU=Groups,OU=DE" + $DomainName)

Howard Bullock
(KiX Supporter)
2006-03-10 08:27 PM
Re: Create a group in Active Directory

I have already done the heavy lifting for you.

http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB12&Number=112366


Markus_Hahn
(Fresh Scripter)
2006-03-11 01:56 PM
Re: Create a group in Active Directory


Howard, you made my day. Not only that your script works great, it also showed me where my mistake was. After changing my script like this

$OU = GetObject($ADsPath)
$UserObj = $OU.Create("Group","cn=$GRPName")

it works also. Thanks a lot for your help.


Les
(KiX Master)
2006-03-11 02:07 PM
Re: Create a group in Active Directory

Good to hear. You should however refrain from using vars in strings.