0

爲現有用戶創建郵箱,並且它已成功執行,但我無法看到創建的郵箱。其實我正在使用交換服務器2010和服務器2008r2我使用命令CreateMailBox,但它說它不支持屬性/對象。所以請幫助我編寫一個vbscript來創建Exchange 2010和Server 2008 R2的郵箱。要使用vbscript

這裏是我的腳本

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 

回答

0

一切從我所看到的,VBScript是不與移動到PowerShell的支持。如果您確實需要使用vbscript,則可以使用vbs調用PowerShell並運行相應的cmdlet。除此之外,你可能會想看看不同的解決方案。

$password = Read-Host "Enter password" -AsSecureString 
New-Mailbox -UserPrincipalName [email protected] -Alias testuser -Database "Mailbox Database 2048259302" -Name testuser –OrganizationalUnit Users -Password $password -FirstName test -LastName user -DisplayName "Test User" -ResetPasswordOnNextLogon $true 
+0

感謝您的幫助,但請讓我知道如何通過VBS調用PowerShell腳本,因爲我沒有對PowerShell的任何想法,我想通過VBScript來創建它只是 – user3472113

+0

$密碼=讀 - 主機「輸入密碼 「-AsSecureString 新郵箱-UserPrincipalName [email protected] -Alias TESTUSER -Database 」郵箱數據庫2048259302「 雜牌TESTUSER -OrganizationalUnit 用戶 - 密碼密碼@ bng1 -FirstName測試-LastName用戶 -DisplayName」 測試用戶「-ResetPasswordOnNextLogon $ True – user3472113

+0

嗨,這是我嘗試使用powershell的腳本,但我得到的錯誤如下缺少一元運算符後的表達式' - ' – user3472113