content-location: file:///C:/8D38CB29/file9481.htm content-transfer-encoding: quoted-printable content-type: text/html; charset="us-ascii" mime-version: 1.0 Création d’un compte NT et de sa Boîte (Exchange= 200X)

Création d’un co= mpte NT et de sa Boîte (Exchange 200X)

 

'*****<= o:p>

'***     Useradd.vbs -  Creates new user accounts f= rom 'First Name'/'Last Name' pairs passed as parameters.

'***        =             &n= bsp;           &nbs= p;            =             &n= bsp;      Also creates associated Exchange account.

'***

'***     Usage:        =             &n= bsp;    useradd.vbs <First Name> <Last Name>

'***

'*****<= o:p>

&n= bsp;

'***     Declare variable= s used throughout the script.

&n= bsp;

        =     Public DomName

        =     Public HomeServer

        =     Public FirstName

        =     Public LastName

        =     Public UserName

        =     Public Debug

        =     Public Network

&n= bsp;

'***     Set Debug =3D Tr= ue to have debugging messages print out.

&n= bsp;

'        =    Debug =3D True

&n= bsp;

'***     Define some constants.  Change these to r= eflect your domain enviroment.

&n= bsp;

        =     DomName =3D "Domain"

        =     HomeServer =3D "homeserver= "

        =     LogonScript =3D "login.bat= "

        =     InitialPassword =3D "badpa= ssword"

        =     UserHomeUpperDir =3D "\\" & HomeServer & "\Users$"

        =     root =3D "WinNT://" & HomeServer & "/"

&n= bsp;

'***     Create the vario= us objects

&n= bsp;

        =     Set Domain =3D GetObject("WinNT://" & DomN= ame)

        =     Set HomeServerObj =3D GetObject("WinNT://" & DomN= ame & "/" & HomeServer & &qu= ot;/lanmanserver")

        =     Set Shell =3D WScript.CreateObject("WScript.Shell"= ;)

        =    

        =     Cleanup

&n= bsp;

        =     GetUserInfo UserName, FirstName, LastName=

&n= bsp;

        =     CreateUser UserName, FirstName, LastName=

&n= bsp;

        =     AddMailBox UserName, FirstName, LastName

&n= bsp;

        =     CreateHomeShare UserName= , FirstName, LastName=

&n= bsp;

        =     Cleanup

&n= bsp;

'*****<= o:p>

'***

'***     Various subrouti= nes used throughout the script.

'***

'*****<= o:p>

&n= bsp;

'*****<= o:p>

'***     Create the user = account

'*****<= o:p>

&n= bsp;

Sub CreateUser(ByVal UserName, ByVal FirstName, ByVal LastName)

        =     If Debug =3D True then

        =             &n= bsp;   Wscript.Echo "Creating User Account"<= /o:p>

        =     End If

&n= bsp;

&n= bsp;

        =     UserHome =3D "\\" & HomeServer & "\" & UserName & "$"

&n= bsp;

        =     Set NewUser =3D Domain.Create("user",UserName)

        =     NewUser.FullName =3D FirstName<= /span> & " " & LastName<= /span>

        =     NewUser.HomeDirectory =3D UserH= ome

        =     NewUser.LoginScript =3D LogonSc= ript

    &nbs= p;       NewUser.Description =3D "Description"=

 

'        =    If Debug =3D True then

'        =             &n= bsp;  DebugPrint

'        =    End If

&n= bsp;

        =     NewUser.SetInfo

        =     NewUser.SetPassword(InitialPassword)

        =     Set NewUser =3D Nothing

End Sub=

&n= bsp;

'*****<= o:p>

'***     Create the user'= s home directory and Share

'*****<= o:p>

&n= bsp;

Sub CreateHomeShare(ByVal UserName, ByVal FirstName, ByVal LastName)

&n= bsp;

        =     If Debug =3D True then

        =             &n= bsp;   Wscript.Echo "Creating Home Directory and Share= s for " & UserName=

        =     End If

&n= bsp;

        =     Set Network =3D WScript.CreateObject<= /span>("WScript.Network&qu= ot;)

        =     Network.MapNetworkDrive "x:= ", UserHomeUpperDir

&n= bsp;

        =     Set FileSys =3D CreateObject("Scripting.FileSystemObjec= t")

&n= bsp;

        =     FileSys.CreateFolder("x:\" & UserName<= /span>)

        =    

        =     UserShare =3D UserNameVar & "$"

&n= bsp;

        =     set newshare =3D HomeServerObj.create("fileshare", UserName & "$")

        =     newshare.path=3D"U:\" & UserName

        =     newshare.MaxUserCount=3D-1<= /p>

        =     newshare.setinfo

&n= bsp;

        =     If Debug =3D True then

        =             &n= bsp;   Wscript.Echo "cacls x:\" & UserName & " /t /g " & UserName & ":F"

        =     End If

&n= bsp;

        =     Shell.run "soon \\akili-dfw0 1 net accounts /sync",1,true

        =     Shell.run "sleep 10",1= ,true

        =     Shell.run "cacls x:= \" & UserName & "= ; /T /E /C /G " & UserName & ":F",1,true

        =     Shell.run "cacls x:= \" & UserName & "= ; /T /E /C /R Everyone",1,true

        =    

End Sub=

&n= bsp;

'*****<= o:p>

'***     Preform cleanup operations prior to shutting down

'*****<= o:p>

&n= bsp;

Sub Cle= anup

&n= bsp;

        =     Set WSHNetwork =3D WScript.CreateObject("WScript.Network&qu= ot;)

        =     Set colDrives =3D WSHNetwork.= EnumNetworkDrives

&n= bsp;

        =     If colDrives.Count <> 0 Then

        =             &n= bsp;   For i =3D 0 To colDrives.Count - 1 Step 2

        =             &n= bsp;           &nbs= p;  IF colDrives(i) =3D "X:" THEN<= /p>

        =             &n= bsp;           &nbs= p;            =   WSHNetwork.RemoveNetworkDrive "X:"

        =             &n= bsp;           &nbs= p;  End IF

        =             &n= bsp;   Next

        =     END IF

End Sub=

&n= bsp;

'*****<= o:p>

'***     Print some debug information

'*****<= o:p>

&n= bsp;

Sub DebugPrint

        =     DebugText =3D "First name: " & FirstName

        =     DebugText =3D DebugText = & vbCRLF

        =     DebugText =3D DebugText = & "Last name: " & LastName

        =     DebugText =3D DebugText = & vbCRLF

        =     DebugText =3D DebugText = & "Full name: " & NewUser.FullName=

        =     DebugText =3D DebugText = & vbCRLF

        =     DebugText =3D DebugText = & "User Name: " & UserName

        =     DebugText =3D DebugText = & vbCRLF

        =     DebugText =3D DebugText = & "Home Directory: " & NewUser.HomeDirect= ory

        =     DebugText =3D DebugText = & vbCRLF

        =     DebugText =3D DebugText = & "Login Script: " & NewUser.LoginScript<= /span>

        =     DebugText =3D DebugText = & vbCRLF

        =     DebugText =3D DebugText = & "Description: " & NewUser.Description

&n= bsp;

        =     Wscript.echo DebugText

End Sub=

&n= bsp;

'*****<= o:p>

'***     Get new user's n= ame from command line parameters

'*****<= o:p>

&n= bsp;

Sub GetUserInfo(ByRef UserName, ByRef FirstName, ByRef LastName)

        =     set oArgs=3Dwscript.arguments

&n= bsp;

        =     If oArgs.Count <> 2 Then<= /span>

        =             &n= bsp;   WScript.Echo "Usage: usera= dd <First name> <Last name>"

        =             &n= bsp;   Quit

        =     Else

        =             &n= bsp;   FirstName =3D Proper(oArgs.item(0))

        =             &n= bsp;   LastName =3D Proper(oArgs.item(1))

        =             &n= bsp;   UserName =3D Left(FirstNa= me,1) & LastName

        =     End If

End Sub=

&n= bsp;

'*****<= o:p>

'***     Create a "proper"-case name

'*****<= o:p>

&n= bsp;

Functio= n Proper (TextIn)

        =     Proper =3D UCase(left(TextIn,1)) & LCase(mid(TextIn,2))

End Fun= ction

&n= bsp;

'*****<= o:p>

'***     Create the new u= ser's Exchange mailbox

'*****<= o:p>

Sub AddMailBox(ByVal UserName, ByVal FirstName, ByVal LastName)

&n= bsp;

        =     Dim namespaceLDAP

        =     Dim contExchRecipe

        =     Dim objMessageStore

        =     Dim objMailbox

        =     Dim strFirstName

&n= bsp;

        =     Dim strLastName

        =     Dim strDisplayName

        =     Dim strAlias

&n= bsp;

        =     Dim strDirectoryName

        =     Dim str1

        =     Dim str11

&n= bsp;

        =     Dim str2

        =     Dim str3

        =     Dim str

        =     Dim SMTPAddress

        =     Dim aOtherMailbox(1)

        =     Dim strMail

        =     Dim strMTA

        =     Dim strTemp

        =     Dim strPos

        =     Dim strServerName

&n= bsp;

        =     Dim strOU

        =     Dim strO

        =     Dim strUserName

        =     Dim strDomain

        =     Dim strPassword

        =     Dim strSMTPFQDN

        =     Dim intK

        =     Dim strC

 

        =     Dim oSID

 

        =     strFirstName<= /span> =3D FirstName

        =     strLastName =3D LastName

&n= bsp;

        =     strDisplayName =3D strFirstName & " " & strLastName

        =     strAlias =3D UserName

        =     strDirectoryName =3D strAlias

        =     strServerName =3D "<= span class=3DSpellE>EXServer"

        =     strOU =3D "Organizat= ion"

        =     strO =3D "Site"=

&n= bsp;

        =     str1 =3D "LDAP://" + = strServerName + "/cn=3DRecipients,= ou=3D" + strOU + ",o=3D" +strO

        =     str11 =3D "LDAP://" + = strServerName + "/cn=3DMicrosoft Private MDB,cn=3D" + strServerName + ",= cn=3DServers,cn=3DConfiguration,ou=3D" + strOU + ",o=3D" + strO

&n= bsp;

' Use these lines if you must ru= n this procedure from other than the Exchange Admin Account

&n= bsp;

        =     Set contExchRecips =3D GetObject(str1)

        =     Set objMailbox =3D contExchRecips.Create("organizationalPerson", "cn=3D" + CStr<= /span>(strDirectoryName))

&n= bsp;

        =     Set objMessageStore =3D GetObject(str11)

&n= bsp;

' Use Message Store (guarenteed to exist on any Exchange server) to get FQDN of Exchange site

        =     objMessageStore.GetInfo

&n= bsp;

        =     strMail =3D objMessageStore.Get("mail")

&n= bsp;

        =     strPos =3D InStr(strMail, "@")

        =     strSMTPFQDN =3D Mid(strMail, strPos, Len(strMail))

&n= bsp;

'Remove= all spaces from Alias.

        =     strTemp =3D Replace(strAlias, " ", "")

&n= bsp;

        =     strSMTPAddress =3D strTemp + strSMTPFQDN

&n= bsp;

        =     strMTA =3D "cn=3DMi= crosoft MTA,cn=3D" + strServerName +",cn= =3DServers,cn=3DConfiguration,ou=3D" + strOU + ",o=3D" + strO

        =     aOtherMailbox(0) =3D "MS$" + strO + "/" + <= span class=3DSpellE>strOU + "/" + strAlia= s

        =     aOtherMailbox(1) =3D "CCMAIL$" + strAlias + " at= " + strOU

&n= bsp;

        =     objMailbox.Put "mailPrefer= enceOption", 0

        =     objMailbox.Put "givenName<= /span>", CStr(strFirstName)

        =     objMailbox.Put "sn&= quot;, CStr(= strLastName)

        =     objMailbox.Put "cn&= quot;, CStr(= strDisplayName)

        =     objMailbox.Put "uid= ", CStr(= strAlias)

        =     objMailbox.Put "Home-MTA", CStr(strMTA)

        =     objMailbox.Put "mail", CStr(strSMTPAddress)

'** MAPI-Recipient is same as "Allow rich text in messages" checkbox= .

'        =    objMailbox.Put "MAPI-Recipient", True=

&n= bsp;

        =     objMailbox.PutEx 2, "other= Mailbox", (aOtherMailbox)

&n= bsp;

        =     objMailbox.Put "rfc822Mailbox", CStr(= strSMTPAddress)

        =     objMailbox.Put "textEncode= dORaddress", CStr("c=3DFR;a=3D ;p=3D" + strO + ";o=3D" + strOU + ";s=3D" = + strLastName + ";g=3D" + strFirstName + ";")

&n= bsp;

        =     Set oSID =3D CreateObject("SID.CSID")

&n= bsp;

        =     oSID.UserName =3D strAlias   

  

        =     oSID.DomainName =3D DomName

&n= bsp;

        =     txtSID =3D oSID.ExchangeSID

&n= bsp;

        =     objMailBox.Put "Assoc-NT-Account", CStr(= oSID.ExchangeSID)

&n= bsp;

        =     objMailbox.SetInfo

&n= bsp;

End Sub=

&n= bsp;

Sub AssocNTAccount

Dim u

Set u = =3D GetObject("WinNT://domain/user")

&n= bsp;

Dim sid

sid =3D u.Get("O= bjectSID")

strsid =3D ""

For i =3D (LBou= nd(sid) + 1) To (UBound(sid) + 1)

strsid =3D strsid & Hex(AscB(MidB(sid, i, 1)) \ 16) & Hex(AscB(= MidB(sid, i,

1)) Mod= 16)

Next

&n= bsp;

MsgBox strsi= d

objMailbox.Put "Assoc-NT-Account&quo= t;, CStr(= strsid)

objMailbox.SetInfo

 

 

end sub.