ActiveXPoSH syntax?

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 2 weeks 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
schullo
Posts: 2
Last visit: Wed Sep 10, 2008 12:31 pm

ActiveXPoSH syntax?

Post by schullo »

Greetings!
I am new to using the Sapien ActiveXPosh COM object. While the tool has excellent potential, the documentation that comes with the tool is not great and there are no useful examples on the web right now.
Specifically, I need to make sure a couple of profiles are loaded when I make a Powershell command call. A great example is the Exchange 2007 Management Shell extensions.
I know the ".INIT()" method exists for this purpose but I cannot get the syntax to work correctly.
Ideas?
Thanks in advance.
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

ActiveXPoSH syntax?

Post by jhicks »

Let me see if I can come up with some examples.
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

ActiveXPoSH syntax?

Post by jhicks »

The Init() method is merely used to create a PowerShell instance. You can specify whether you want it to run your PowerShell profiles or not. In your PowerShell profile needs to have the Add-PSSnapin commands to load the Exchange 2007 snapins. Configure your profile and test it in PowerShell. Once you have everything loaded you want, then in your VBScript use ActiveXPosh.Init(vbTrue)
User avatar
sabofx
Posts: 10
Last visit: Tue Sep 29, 2015 3:24 pm

ActiveXPoSH syntax?

Post by sabofx »

Dear developer!It would be really great if you would be able to fix the error I've been getting.I am trying to 'mail enable' an (already existing) AD user on our Exchange 2007 platform from an ASP web page using the ActiveXPoSH object.But when I try to execute Exchange PowerShell commands from a vbscript I got a really weird errors.Example:The Username (to be mail enabled) is "InboardingabvT"The syntax from PowerShell would be:Enable-Mailbox -Identity broadband.lan/NEWCO/USERS/InboardingabvT -Alias InboardingabvT -Database SVMBEXSG02MBXSTORE02This command works without errors when executed directly from a PowerShell console.Example script (EnableMB.vbs) that should 'mail enable' a user:MainSub Main Set args = WScript.Arguments If args.count > 0 Then UserName = args(0) Randomize intStorageNumber= Int((19*Rnd)+1) 'Choose Random stores/storage groups where mailboxes are created. strStorageNumber = Right("0"&intStorageNumber,2) Set objActiveXPosh = CreateObject("SAPIEN.ActiveXPoSH") ' Create the PowerShell connector object success = objActiveXPosh.Init(vbFalse) 'Do not load profiles objActiveXPosh.OutputMode = OUTPUT_BUFFER ' Set the output mode to buffer objActiveXPosh.Execute("Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin") objActiveXPosh.Execute("Enable-Mailbox -Identity broadband.lan/NEWCO/USERS/"&UserName&" -Alias "&UserName&" -Database SVMBEXSG"&strStorageNumber&"MBXSTORE"&strStorageNumber) objActiveXPosh.ClearOutput() ' Empty the output buffer Set objActiveXPosh = Nothing Set args = Nothing End IfEnd SubThe username is entered as a command line parameter to the script itself.The script is launched from cmd (as domain/exchange admin) like this:cscript EnableMB.vbs usernameResulting errors on console output:C:temp>cscript EnableMB.vbs inboardingabvTMicrosoft (R) Windows Script Host Version 5.7Copyright (C) Microsoft Corporation. All rights reserved.Name Alias ServerName ProhibitSendQuo ta---- ----- ---------- ---------------InboardingabvT inboardingabvT svmbex unlimitedWARNING: An unexpected error has occurred and debug information is being generated: Value of '-1' is not valid for 'Value'. 'Value' should be between 'minimum'and 'maximum'.Parameter name: ValueERROR: Enable-Mailbox : Value of '-1' is not valid for 'Value'. 'Value' should be betwERROR: een 'minimum' and 'maximum'.ERROR: Parameter name: ValueERROR: At line:1 char:15ERROR: + Enable-Mailbox <<<< -Identity broadband.lan/NEWCO/USERS/inboardingabvT -AliaERROR: s inboardingabvT -Database SVMBEXSG17MBXSTORE17The command is actually executed (when launched from the vbscript). The user is mail enabled, but it doesn't look like it judging from the error.When launched from an ASP page the command is not executed at all...My setup consists out of:- Windows Server 2003 R2 32bits SP2 standard edition- Exchange 2007 SP1- PowerShell v1.0- ASP- IIS 6Also tried on: (got same error)- Windows Server 2008 32bits SP1 enterprise edition- PowerShell v 2.0 CTP- IIS 7PowerShell commands that are unrelated to Exchange (like the example in the PDF you provided) seem to run fine using ActiveXpoSH.Do you have any ideas why I get these strange errors?Your help is much appreciated!!Kind regards,Joost KuinSystem Admin / Developer / Office SecurityBusiness systems & platformsOnline Breedband BV
User avatar
Alexander Riedel
Posts: 8489
Last visit: Thu Apr 18, 2024 9:59 am
Answers: 20
Been upvoted: 37 times

ActiveXPoSH syntax?

Post by Alexander Riedel »

It's a problem with the progress output in ActiveXPosh.
We'll put up a fix shortly.
We have never tested this from an ASP page, so I can't really say what the cause might be.
Alex
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8489
Last visit: Thu Apr 18, 2024 9:59 am
Answers: 20
Been upvoted: 37 times

ActiveXPoSH syntax?

Post by Alexander Riedel »

Re-download please and install. I can't guarantee this fixes it, so please let us know.

Alex
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
sabofx
Posts: 10
Last visit: Tue Sep 29, 2015 3:24 pm

ActiveXPoSH syntax?

Post by sabofx »

Hi Alexander!I must say that I am stunned by your swift response. Thanx for that!I installed the latest release. The errors in the output have disappeared and I have it working from ASP!The only downside is that it only works when I put the website in an application pool that runs under the identity of an domain administrative account. When I can find the time, I'll do some more testing.I hope you can continue to improve it. (Maybe add some additional documentation and/or examples).Any chance you could do some testing using your object from ASP to perform Exchange tasks?Thanx again & greetzJoost KuinSystem Admin / Developer / Office SecurityBusiness systems & platformsOnline Breedband BV
sabofx2008-09-02 08:44:43
User avatar
sabofx
Posts: 10
Last visit: Tue Sep 29, 2015 3:24 pm

ActiveXPoSH syntax?

Post by sabofx »

Hi Alexander!I think that there is a problem with the "ActiveXPosh.Init" property in combination with "objActiveXPosh.Eval".The command "objActiveXPosh.Init(vbTrue)" returns TRUE, but cmdlets from my profile are unavailable when evaluating a powershell command.The code below is supposed to load the "PSSnapin Microsoft.Exchange.Management.PowerShell.Admin" from my profile.It should then evaluate the command "get-mailbox UNKNOWNUSER".I expected it to return FALSE as we don't have a user by the name of 'UNKNOWNUSER'. :-)WScript.Echo EvalPowerShellCommand("get-mailbox UNKNOWNUSER")'===========================================================================' Evaluate Powershell command and return result as boolean'===========================================================================Function EvalPowerShellCommand(strPsCmd) Set objActiveXPosh = CreateObject("SAPIEN.ActiveXPoSH") success = objActiveXPosh.Init(vbTrue) ' load profile EvalPowerShellCommand = objActiveXPosh.Eval(strPsCmd) Set objActiveXPosh = NothingEnd FunctionInstead, where it evaluates the "get-mailbox" command, the script exits with error:
"System.Management.Automation: The term 'get-mailbox' is not recognized as a cmdlet, function, operable program, or s
cript file. Verify the term and try again."It appears to me that the "Init" property doesn't work in combination with "objActiveXPosh.Eval".Can you please look into it?Btw, I DO NOT have this problem when using "objActiveXPosh.Execute"!For example, this code works just fine"WScript.Echo ExecPowerShellCommand("get-mailbox JohnD",100)'=========================================================================='Execute Powershell command on local machine and return output as string'==========================================================================Function ExecPowerShellCommand(strPsCmd,intWidth) Const OUTPUT_CONSOLE = 0 Const OUTPUT_WINDOW = 1 Const OUTPUT_BUFFER = 2 Set objActiveXPosh = CreateObject("SAPIEN.ActiveXPoSH") success = objActiveXPosh.Init(vbTrue) objActiveXPosh.OutputMode = OUTPUT_BUFFER ' Set output to buffer objActiveXPosh.OutputWidth = intWidth objActiveXPosh.Execute(strPsCmd) ExecPowerShellCommand = objActiveXPosh.OutputString objActiveXPosh.ClearOutput() Set objActiveXPosh = NothingEnd FunctionThanx for your support!!
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

ActiveXPoSH syntax?

Post by jhicks »

The Eval method returns True if an object is returned. It works fine for me using a cmdlet loaded from a snapin from my profile (not Exchange). If you run your expression directly in PowerShell like this: $m=Get-Mailbox UNKnownuserWhat happens? Does $m exist? Can you try this with other non-Exchange cmdlets? We need to see if the problem is with the control or perhaps the way the Exchange cmdlets work.
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

ActiveXPoSH syntax?

Post by jhicks »

I tried again with a PowerShell community extension that I knew would not return an object and I get the same result. I verified it in Powershell:#clipboard has textPS C:> $e=get-clipboardPS C:> $e -is [object]True#copy non text to clipboard and repeatPS C:> $e=get-clipboardPS C:> $e -is [object]FalseI suspect your Get-Mailbox command is working as expected, that is, no mailbox is returned for a non-existent user. Its just that the error message from PowerShell is misleading.
This topic is 15 years and 2 weeks 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.