ActiveXPosh and Enable-Mailbox

This forum can be browsed by the general public. Posting is no longer allowed as the product has been discontinued.
This topic is 15 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
mrove
Posts: 3
Last visit: Sun Dec 07, 2008 9:47 am

ActiveXPosh and Enable-Mailbox

Post 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

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: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

ActiveXPosh and Enable-Mailbox

Post by Alexander Riedel »

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
Last visit: Sun Dec 07, 2008 9:47 am

ActiveXPosh and Enable-Mailbox

Post 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
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

ActiveXPosh and Enable-Mailbox

Post 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.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
mrove
Posts: 3
Last visit: Sun Dec 07, 2008 9:47 am

ActiveXPosh and Enable-Mailbox

Post 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.
This topic is 15 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.