0

and it is getting successfully executed but i am not able to see the mailbox created. Actually i am using exchange server 2010 and server 2008r2 i am using the command CreateMailBox , but it says it does not support the property/object. So please help me writing a vbscript to create a Mailbox for exchange 2010 and server 2008 R2.

Here is my script

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
Rich
  • 4,134
  • 3
  • 26
  • 45

1 Answers1

-1

From everything I've seen, vbscript isn't supported with the move to PowerShell. You could use vbs to call PowerShell and run the appropriate cmdlet if you really need to use vbscript. Other than that you'll probably want to look at a different solution.

$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 
codingChris
  • 697
  • 4
  • 8
  • Thanks for your help, but please let me know how to call a powershell script through vbs because i dont have any idea about powershell and i want to create it through vbscript only – user3472113 Apr 29 '14 at 05:23
  • $password = Read-Host "Enter password" -AsSecureString New-Mailbox -UserPrincipalName testuser@mlexchange.net -Alias testuser -Database "Mailbox Database 2048259302" -Name testuser –OrganizationalUnit users -Password password@bng1 -FirstName test -LastName user -DisplayName "Test User" -ResetPasswordOnNextLogon $True – user3472113 Apr 29 '14 at 05:25
  • Hi this is the script i tried with powershell, but i am getting the error as follows Missing expression after unary operator '-' – user3472113 Apr 29 '14 at 05:29
  • Edited the answer. Your syntax looks correct, you just need to pass in the password as a secure string or the one you captured. Unless I missed something that is mistyped, that should work. – codingChris Apr 30 '14 at 00:43