Page 1 of 1

ActiveXPosh and Enable-Mailbox

Posted: Sat Dec 06, 2008 10:10 am
by mrove
I have been struggling all day with this and can't seem to make
it work.

ActiveXPosh and Enable-Mailbox doesn't do anything for me
in my script. ActiveXPosh is working for me on other commands like
the ActiveXPosh.Eval("get-process winword") example in the
sample SAPIEN script.

Also, I can run the Enable-Mailbox command in Powershell and it creates my
mailbox but within the code below it does nothing.

Can someone please help me?
Has anyone got ActiveXPosh and Enable-Mailbox to work for them?

I'd appreciate any help or advice. Thanks!

'My Enable Mailbox script

Option Explicit

Dim ActiveXPosh
Dim strStorageGroup
Dim Command


Function CreateActiveXPosh()
Dim success
Set ActiveXPosh = CreateObject("SAPIEN.ActiveXPoSH")
success = ActiveXPosh.Init(vbFalse)
If success <> 0 then
WScript.Echo "Init failed"
end if
ActiveXPosh.OutputMode = OUTPUT_CONSOLE
End Function


strStorageGroup = """LABMBX01Third Storage GroupMailboxDB2"""

Command = "Enable-Mailbox -Database " & strStorageGroup

ActiveXPosh and Enable-Mailbox

Posted: Sun Dec 07, 2008 4:54 am
by Alexander Riedel
success = ActiveXPosh.Init(vbTrue)

Otherwise yor profile will not be executed, which most likely contains the snapin(s) you need.


ActiveXPosh and Enable-Mailbox

Posted: Sun Dec 07, 2008 10:21 am
by mrove
Thanks for your help Alex.

Unfortunately, when I changed it to vbTrue and ran the
script I got the message "Init failed"

My snapin for Exchange which is:
Add-PSSnapIn Microsoft.Exchange.Management.PowerShell.Admin

is already loaded. And I can run Enable-Mailbox directly in
Powershell and the mailbox gets created so everything is working there.
I'm just stuck on getting ActiveXPosh to execute it for me.

Any other ideas?

mrove2008-12-07 17:22:04

ActiveXPosh and Enable-Mailbox

Posted: Sun Dec 07, 2008 10:27 am
by Alexander Riedel
Ok, run Init(VBFalse)
and add this line:
ActiveXPosh.Execute("Add-PSSnapIn Microsoft.Exchange.Management.PowerShell.Admin")

You are most likely running a specialized shell that already loads that snapin.

ActiveXPosh and Enable-Mailbox

Posted: Sun Dec 07, 2008 10:45 am
by mrove
Yep, that works!

I swear I tried that yesterday but I was at it
(and the AD user account script I am embedding it in)
for about 6 hours so maybe I didn't get it all in the
right sequence.

I took the Add-PSSnapIn out of the script and was invoking it
via Powershell directly and the script never worked.

Anyways, it is working now.

Thank you very much for taking time out to assist me!
I appreciate it.