running script that creates AD users from another workstation
From: Gentian Hila (GentianHila_at_discussions.microsoft.com)
Date: 08/10/04
- Next message: Jerold Schulman: "Re: Create Multiple Shares"
- Previous message: Jerold Schulman: "Re: Scripting Windows Automatic Updates"
- Next in thread: Manfred: "Re: running script that creates AD users from another workstation"
- Reply: Manfred: "Re: running script that creates AD users from another workstation"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 10 Aug 2004 07:47:02 -0700
Hi,
I have the following script that creates users on AD and it runs fine on the
Domain Controller, but this is going to be part of bigger script that reads
the information from a db and updates AD and the blackboard. So we think that
the script might run someother machine (a domain member) rather than in AD.
I do not know how to make it run from another machine, a domain member.
I guess should be something simple to make it work but I have no clue.
Any idea is appreciated.
Here is the script:
call
adduser(WScript.Arguments(0),WScript.Arguments(1),WScript.Arguments(2),WScript.Arguments(3) )
sub adduser(strName, strLast, strpasswd, strgroup)
' Create the username
Dim usern
Dim arrGrPath
usern=lcase(strLast & Left(strName,1))
'*****************************************
Dim strContainer
Dim oContainer, oUser
sLDAPDomain = "DC=TEST,DC=COM"
'*****************************************
'Test what group belongs the user, and create appropriate containers for the
account
'and for the Exchange Mailbox
if lcase(strgroup)="students" then
'user container
strContainer="ou=Students,ou=Accounts"
'security group container
arrGrPAth=Array("CN=admin,OU=Students,ou=Accounts",_
"CN=Students,OU=Students,ou=Accounts")
'Exchange Containers
szStoreName = "Mailbox Store (BACKTEST)"
szStorageGroup = "First Storage Group"
End if
if lcase(strgroup)="staff" then
'user container
strContainer="ou=Staff,ou=Accounts"
'security group container
arrGrPAth=Array("CN=Staff,OU=Staff,ou=Accounts")
'Exchange Containers
szStoreName = "Mailbox Store (BACKTEST)"
szStorageGroup = "First Storage Group"
End if
'*****************************************************
'Create an instance of the container, turn on error handling
On error resume next
Set oContainer=GetObject("LDAP://"& strContainer & ",dc=test,dc=com")
If err.number<>0 Then
WScript.Echo(hex(err.number))
WScript.Echo(Err.Description)
Err.Clear
End If
'Try to create the user,
Set oUser=oContainer.Create("User", "CN="&strName&" "&strLast)
oUser.Put "samAccountName", usern
oUser.Put "givenName", strName
oUser.Put "sn", strLast
oUser.Put "userPrincipalName", usern&"@test.com"
oUser.SetInfo
'error handling here checks if the user already exists
If err.number<>0 Then
WScript.Echo(hex(err.number))
If err.number=-2147019886 Then
WScript.Echo("The user already exists")
End If
else
'If the user is created, then set the attibutes and create a mailbox
oUser.SetPassword lcase(strpasswd)
oUser.AccountDisabled=false
oUser.Description="User was created on "& MonthName(month(date()))&"
"&Day(date())&", "&Year(date())
oUser.pwdLastSet=0
'Create a profile and a home directory only for students"
If lcase(strgroup)="students" then
oUser.Profile="\\backtest\profile\"&usern
oUser.homeDirectory="\\backtest\profile\"&usern
oUser.homeDrive="X"
End if
For Each GrPath in arrGrPath
'Set the path to the security group and create an instance
gpstr = "LDAP://"& GrPath &", DC=test,DC=com"
set oGroup = GetObject(gpstr)
'now add the user to the group
oGroup.Add oUser.ADsPath
Next
'Set the exchange path where the mailbox will be created
Set oMailbox = oUser
szServerName = "BACKTEST"
szAdminGroup = "First Administrative Group"
szExchangeOrg = "First Organization"
sMBXStoreDN = "LDAP://CN="&szStoreName & _
",CN="& szStorageGroup & _
",CN=InformationStore" & _
",CN="& szServerName & _
",CN=Servers" & _
",CN="&szAdminGroup & _
",CN=Administrative Groups" & _
",CN="&szExchangeOrg & _
",CN=Microsoft
Exchange,CN=Services,CN=Configuration," & _
sLDAPDomain
'create te actual mailbox
oMailbox.CreateMailbox sMBXStoreDN
oUser.SetInfo
Set oUser=Nothing
Set oMailbox=Nothing
End If
Err.Clear
On Error Goto 0
Set oContainer= Nothing
WScript.Echo "Finished"
End Sub
- Next message: Jerold Schulman: "Re: Create Multiple Shares"
- Previous message: Jerold Schulman: "Re: Scripting Windows Automatic Updates"
- Next in thread: Manfred: "Re: running script that creates AD users from another workstation"
- Reply: Manfred: "Re: running script that creates AD users from another workstation"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|