Create user with vbs in Exchange 2007


I have the following vbs code that creates a user in AD and adjoining Exchange account.  This code has worked fine with Exchange 2003, but with Exchange 2007 the Exchange account that is created is of type legacy and does not work.  Help&.
Set objOU = GetObject("LDAP://cn=users,dc=interconsult,dc=com") 
Set objUser = objOU.Create("User", "cn=" & user)
objUser.Put "sAMAccountName",user
MBXStoreDN ="LDAP://CN=Mailbox Database,CN=First Storage Group,CN=InformationStore,CN=" & MailServer & ",CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=Interconsult ASA,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=interconsult,DC=com"
Set ExchUser = objUser

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is script I used... it takes a csv file for input

Example CSV file

Note... you can hardcode the DB Name if you wish.
Param($file,$db = (Get-MailboxDatabase).Distinguishedname,[switch]$whatif)
Write-host "Adding Users from File $file"
Write-Host "Using Database $db"
if(!(test-path $file)){write-host "$file is not valid file"}
$users = Import-Csv $file
foreach($user in $users)
    $password = ConvertTo-SecureString -String $user.Password -AsPlainText -force
    if($whatif){New-Mailbox -database $db -Name $User.Name -Password  $password -UserPrincipalName $user.UserPrincipalName -FirstName $user.FirstName -LastName $user.LastName -whatif}
    else{New-Mailbox -database $db -Name $User.Name -Password  $password -UserPrincipalName $user.UserPrincipalName -FirstName $user.FirstName -LastName $user.LastName}

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
any news here?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.