ActiveXPosh and Enable-Mailbox

Support for all customers who have purchased or received a Productivity Pack Support product license. This forum does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
mrove
Posts: 3
Joined: Sat Dec 06, 2008 10:10 am

ActiveXPosh and Enable-Mailbox

Post by mrove » Sat Dec 06, 2008 10:10 am

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

Const OUTPUT_CONSOLE = 0
Const OUTPUT_WINDOW = 1
Const OUTPUT_BUFFER = 2

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

CreateActiveXPosh

strStorageGroup = """LABMBX01Third Storage GroupMailboxDB2"""

Command = "Enable-Mailbox jdoe@mydomain.com -Database " & strStorageGroup
ActiveXPosh.Execute(Command)

User avatar
Alexander Riedel
Posts: 6873
Joined: Tue May 29, 2007 4:43 pm

ActiveXPosh and Enable-Mailbox

Post by Alexander Riedel » Sun Dec 07, 2008 4:54 am

success = ActiveXPosh.Init(vbTrue)

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

Alex
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
mrove
Posts: 3
Joined: Sat Dec 06, 2008 10:10 am

ActiveXPosh and Enable-Mailbox

Post by mrove » Sun Dec 07, 2008 10:21 am

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

User avatar
Alexander Riedel
Posts: 6873
Joined: Tue May 29, 2007 4:43 pm

ActiveXPosh and Enable-Mailbox

Post by Alexander Riedel » Sun Dec 07, 2008 10:27 am

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.
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
mrove
Posts: 3
Joined: Sat Dec 06, 2008 10:10 am

ActiveXPosh and Enable-Mailbox

Post by mrove » Sun Dec 07, 2008 10:45 am

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.

Locked