使用vbscript为现有用户创建邮箱

时间:2014-04-28 07:25:46

标签: vbscript sql-server-2008-r2 active-directory exchange-server-2010

它已成功执行,但我无法看到创建的邮箱。实际上我使用的是Exchange Server 2010和服务器2008r2我正在使用命令CreateMailBox,但它说它不支持属性/对象。所以请帮我写一个vbscript来创建一个Exchange 2010 for Exchange 2010和server 2008 R2。

这是我的剧本

Dim oIADSUser
Dim oMailbox

Set oIADS = GetObject("LDAP://RootDSE")
strDefaultNC = oIADS.Get("defaultnamingcontext")
'MsgBox FindAnyMDB("CN=Configuration," & strDefaultNC)

'TODO: Use the newly created domain user account to replace the "UserName". 
Set oIADSUser = GetObject("LDAP://CN=UserName,CN=Users," & strDefaultNC)

Set oMailBox = oIADSUser
oMailbox.CreateMailbox FindAnyMDB("CN=Configuration," & strDefaultNC)
oIADSUser.SetInfo

Function FindAnyMDB(strConfigurationNC)
Dim oConnection 
Dim oCommand 
Dim oRecordSet 
Dim strQuery 

' Open the Connection.
Set oConnection = CreateObject("ADODB.Connection")
set oCommand = CreateObject("ADODB.Command")
Set oRecordSet = CreateObject("ADODB.Recordset")

oConnection.Provider = "ADsDSOObject"
oConnection.Open "ADs Provider"

' Build the query to find the private MDB.
strQuery = "<LDAP://" & strConfigurationNC & ">; (objectCategory=msExchPrivateMDB);name,adspath;subtree"

oCommand.ActiveConnection = oConnection
oCommand.CommandText = strQuery
Set oRecordSet = oCommand.Execute

' If you have an MDB, return the first one.
If Not oRecordSet.EOF Then
    oRecordSet.MoveFirst
    FindAnyMDB = CStr(oRecordSet.Fields("ADsPath").Value)
Else
    FindAnyMDB = ""
End If


'Clean up.
oRecordSet.Close
oConnection.Close
Set oRecordSet = Nothing
Set oCommand = Nothing
Set oConnection = Nothing
 End Function

1 个答案:

答案 0 :(得分:-1)

从我所见过的所有内容来看,移植到PowerShell并不支持vbscript。如果确实需要使用vbscript,可以使用vbs调用PowerShell并运行相应的cmdlet。除此之外,你可能想看一个不同的解决方案。

$password = Read-Host "Enter password" -AsSecureString 
New-Mailbox -UserPrincipalName testuser@mlexchange.net -Alias testuser -Database "Mailbox Database 2048259302" -Name testuser –OrganizationalUnit Users -Password $password -FirstName test -LastName user -DisplayName "Test User" -ResetPasswordOnNextLogon $true