Creating Mailbox on Exchange 2003

by SalvaG at 2013-04-03 03:47:49

Hi all,
I’m trying to create a mailbox on Exchange 2003 Server, but with no luck. I’ve looked for the error, but many people had the same issue as me (like http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/a7622a26-5d1e-4d97-b2b3-ba3053946d36.

More URLS :
http://www.mikepfeiffer.net/2010/05/create-an-exchange-2003-mailbox-with-powershell-and-cdoexm/
http://www.codeguru.com/csharp/csharp/cs_internet/mail/article.php/c14009/Enterprise-Powershell-Creating-Mailboxes-in-Exchange-2003.htm

The error is :
Exception calling “InvokeMember” with “5” argument(s): "Object does not match target type."
At line:28 char:28
+ $assembly_type.InvokeMember <<<< (“createmailbox”, $binding_flags, $null, $account.psbase.nativeobject , $MailboxStoreDN)
+ CategoryInfo : NotSpecified: (:slight_smile: [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

Here is the full code:


Function Add-2003Mailbox {
[CmdletBinding()]
param(
[Parameter()]
[System.String]
$User,
[Parameter()]
[System.String]
$MailboxStore
)

begin {

$assembly = Add-Type -Path “C:\temp\Interop.CDOEXM.dll” -PassThru
$assembly_type = $assembly | ?{$.name -eq “IMailboxStore”}
$binding_flags = [Reflection.BindingFlags] “invokemethod,public”
}

process {
$account = [adsi]“LDAP://$(Get-QADUser $User | select -ExpandProperty DN)”
$mailboxstoreDN = Get-QADObject -LdapFilter “(objectClass=msExchPrivateMDB)” `
-SearchRoot (Get-QADRootDSE ).ConfigurationNamingContext |
?{$
.name -eq $MailboxStore} |
select -ExpandProperty DN

write-host $mailboxstoreDN

$assembly_type.invokemember(“createmailbox”, $binding_flags, $null, $account.psbase.nativeobject , $MailboxStoreDN)
$account.psbase.commitchanges()
}
}

Add-2003Mailbox -User “newusername” -MailboxStore "MBXSG101"


Also, if I cannot do it using PS , anyone have the VBS code to create a mailbox to existent user? I’ll create a temp VBS to create the mailbox and run it from PS
Thanks
by JasonHelmick at 2013-04-03 14:06:38
Hi SalvaG!

This isn’t really a PowerShell versus VBS problem, or really a PowerShell problem – as you have discovered its a Interop.CDOEML.DLL problem. There are several descriptions of getting CDOEML into Interop but as the years have gone by, each of these now has it quirks and issues. I have used the Pfeiffer example in the past and it worked fine, but the error your receiving seems to indicate a problem with making it Interop today – Perhaps one of the Dev’s here can help but until then –

– here’s is a VBS source I have used in the past to build scripts - see if it helps.
http://support.microsoft.com/kb/327079

Jason
by SalvaG at 2013-04-04 03:07:00
Hi Jason
thanks for your reply.
Do you have those DLLs? Or do you know where can I download them?

Meanwhile I’ll try to do it using VBS…

Thanks again,

Salva.
by JasonHelmick at 2013-04-04 07:29:53
I’m sorry - i don’t. The CDOEML.DLL is on any computer that has the management tools, so you can grab that one, but I dont have a working interop one.

Cheers!
by SalvaG at 2013-04-04 12:53:04
Thanks Jason,
I’ve made the interops using Windows XP, management tools DLLs and Windows SDK for framework 2.0, but it seems there is something wrong.
I’ll ask to devs if anyone of them can help me

Thanks again for your help

Cheers,Salva

PS : Can any moderator/admin move this thread to “powershell for devs”? Thanks!
by SalvaG at 2013-04-23 03:29:35
Hi again!
Now I’ve the answer! The problem is shown when you run the script using x64 version of powershell. If you run x86 version it works fine :slight_smile: