Page 1 of 1 1
Topic Options
#158732 - 2006-03-10 04:57 PM Create a group in Active Directory
Markus_Hahn Offline
Fresh Scripter

Registered: 2002-08-07
Posts: 8
Loc: Düsseldorf, Germany
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 ?

Top
#158733 - 2006-03-10 05:52 PM Re: Create a group in Active Directory
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Change $UserObj = $OU.Create("Group","cn=$GRPName") to
$UserObj = $OU.Create("Group","cn="+$GRPName)
_________________________
Today is the tomorrow you worried about yesterday.

Top
#158734 - 2006-03-10 06:19 PM Re: Create a group in Active Directory
Markus_Hahn Offline
Fresh Scripter

Registered: 2002-08-07
Posts: 8
Loc: Düsseldorf, Germany
Already tried that. Unfortunately didn't help.
Top
#158735 - 2006-03-10 06:30 PM Re: Create a group in Active Directory
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
$OU.Create should that not be $OUObj.Create(...), you do not have $OU defined
_________________________
Today is the tomorrow you worried about yesterday.

Top
#158736 - 2006-03-10 07:16 PM Re: Create a group in Active Directory
Shaun_Hill Offline
Getting the hang of it

Registered: 2004-11-15
Posts: 50
Loc: JHB, South Africa
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

Top
#158737 - 2006-03-10 07:32 PM Re: Create a group in Active Directory
Shaun_Hill Offline
Getting the hang of it

Registered: 2004-11-15
Posts: 50
Loc: JHB, South Africa
Also try $OUObj = GetObject("LDAP://OU=Groups,OU=DE" + $DomainName)
Top
#158738 - 2006-03-10 08:27 PM Re: Create a group in Active Directory
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I have already done the heavy lifting for you.

http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB12&Number=112366
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#158739 - 2006-03-11 01:56 PM Re: Create a group in Active Directory
Markus_Hahn Offline
Fresh Scripter

Registered: 2002-08-07
Posts: 8
Loc: Düsseldorf, Germany

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.

Top
#158740 - 2006-03-11 02:07 PM Re: Create a group in Active Directory
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Good to hear. You should however refrain from using vars in strings.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.102 seconds in which 0.056 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org