running script that creates AD users from another workstation

From: Gentian Hila (GentianHila_at_discussions.microsoft.com)
Date: 08/10/04


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



Relevant Pages

  • Re: running script that creates AD users from another workstation
    ... > 'and for the Exchange Mailbox ... > 'security group container ... > 'Create an instance of the container, turn on error handling ...
    (microsoft.public.windows.server.scripting)
  • Re: Playing Sounds
    ... Files have to be in QuickTime format for FileMaker to play them.. ... can double-click an empty container field to record sound directly to it. ... I don't know if the script will wait for the sound to end before moving ...
    (comp.databases.filemaker)
  • Re: Create mutiple PCs in the Domain using vbScripts
    ... You must bind to the OU or container where the object is to be created. ... script to put on the sub OUs of the "Sample" OU? ... either the sAMAccountName or userAccountControl attribute could not be ... Dim objContainer, strComputerName, objComputer ...
    (microsoft.public.scripting.vbscript)
  • Re: Help with script needed
    ... I really love the reflection and could this script be ... Jim was on the right track about the popup being sized to the original image ... But keep in mind that the Width of the Container is determined by the image ... choose to use a different background image for the Popup. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress.stationery)
  • Re: Exporting container fields to specified location
    ... Is there some one who can help me with the script, ... > 1 - Push the button to select a picture to be imported to the container ... > 3 - FMP will make a copy of the file and save it in a specified location ... >>> directory in Filemaker. ...
    (comp.databases.filemaker)