1. 程式人生 > >ad目錄中新增使用者屬性

ad目錄中新增使用者屬性

Sub ADSICreateMailBoxRecipient(MDBName As String, _
                               StorageGroup As String, _
                               Server As String, _
                               AdminGroup As String, _
                               Organization As String, _
                               DomainName As String, _
                               emailname As String, _
                               FirstName As String, _
                               LastName As String)

'MDBName is something like "MyMDB6"
'DomainName is something like "DC=MYDOMAIN3,DC=microsoft,DC=com"
'emailname is something like "jamessmith"

'this assumes the MDB to be a mailbox store.


Dim objUser As IADsUser
Dim objContainer As IADsContainer
Dim objMailbox As CDOEXM.IMailboxStore
Dim recipname As String, recip As String

recip = "CN=" & emailname

' get the container
Set objContainer = GetObject("LDAP://CN=users," + DomainName)

' create a recipient
Set objUser = objContainer.Create("User", recip)
objUser.Put "samAccountName", emailname
objUser.Put "sn", LastName
objUser.Put "givenName", FirstName
objUser.Put "userPrincipalName", emailname
====
dim sSlary
objUser.Put "extensionattribute1",sSlary

objUser.SetInfo
objUser.SetPassword "password"  'let user change it later
objUser.AccountDisabled = False

Set objMailbox = objUser

'Create a mailbox for the recipient
'You cannot create a mailbox using ADSI, so use CDOEXM

objMailbox.CreateMailbox "LDAP://CN=" + MDBName + _
                               ",CN=" + StorageGroup + _
                               ",CN=InformationStore" + _
                               ",CN=" + Server + _
                               ",CN=Servers" + _
                               ",CN=" + AdminGroup + _
                               ",CN=Administrative Groups" + _
                               ",CN=" + Organization + _
                               ",CN=Microsoft Exchange,CN=Services" + _
                               ",CN=Configuration," + DomainName
objUser.SetInfo

End Sub