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 14 years and 11 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
sabofx
Posts: 10
Last visit: Tue Sep 29, 2015 3:24 pm

ActiveXPoSH syntax?

Post by sabofx »

Hi mr Hicks / Alexander!Looking back, the example in my previous post was kind of confusing.I should have mentioned that ActiveXPoSH returns the same error when I evaluate the "get-mailbox" command on a valid user.Let me demonstrate with an example of a command that actualy DOES return an object (when run from a regular PS console)Powershell console:[PS] C:>$m=Get-Mailbox adm.kuin[PS] C:>$mName Alias ServerName ProhibitSendQuota---- ----- ---------- ---------------adm.kuin adm.kuin svmbex unlimitedAs you can see, the mailbox of 'adm.kuin' exists. The command returns a valid object. Therefor, I'll be using this command/mailbox in my next examples to rule out that the errors are caused by the command itself.When I evaluate exactly the same command on the same user from ActiveXPoSH, it fails. It even exits the whole script!script (test.vbs):Function EvalPowerShellCommand(strPsCmd) Set objActiveXPosh = CreateObject("SAPIEN.ActiveXPoSH") success = objActiveXPosh.Init(vbTrue) ' load profile EvalPowerShellCommand = objActiveXPosh.Eval(strPsCmd) Set objActiveXPosh = NothingEnd FunctionWScript.Echo EvalPowerShellCommand("get-mailbox adm.kuin")script output:M:>cscript //nologo m:test.vbsm:test.vbs(9, 5) System.Management.Automation: The term 'get-mailbox' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.The text marked in red clearly states that 'get-mailbox' is an unknown command. The error is invoked by the 'get-mailbox' command.I would get the same error on 'get-mailbox' from a Powershell console whenever the exchange PSSnapin is NOT loaded.In my case, the Exchange PSSnapin is always loaded because I included it in:%windir%system32WindowsPowerShellv1.0profile.ps1This profile applies to all users and all shells.The default PS profile normally also applies to ActiveXPoSH. I can demonstrate this by 'executing' the 'get-mailbox' command instead of 'evaluating' it. As long as I initialize 'ActiveXPosh.Init' with vbTrue, I can execute 'get-mailbox' without any problems.When I use 'ActiveXPosh.Execute' and 'ActiveXPosh.Init' is set to vbFalse, a similar error occurs:The term 'get-mailbox' is not recognized as a cmdlet, function, operable program , or script file. Verify the term and try again.At line:1 char:12+ get-mailbox <<<< adm.kuinThis error is to be expected when I specifically tell it not to load the PS profile prior to executing commands. But I'm just trying to point out the similarity in the error messageRegarding Exchange, it really looks to me that 'ActiveXPosh.Init' only applies to 'ActiveXPosh.Execute' and not 'ActiveXPosh.Eval'.
Are you sure it isn't running in a seperate runspace?In your reply to my previous posting, you asked me to test with another NON-exchange extension. Can you be more specific on which extension you are testing with?btw, I made a wish list for future releases of activeposh. Just curious if you agree that there might be a market for it. Run PS commands on a remote machine(I have achieved something similar by combining ActiveXPosh with psexec (http://technet.microsoft.com/en-us/sysi ... spx)Access to (properties of) objects in powershell from vbs(And the other way around of course)Access to/from variables from powershell(For example it would be great to be able to access from vbscript data that is stored in an array that was created in PowerShell. And the other way around of course)Launch ActiveXPosh object with specific credentials (Usr/Pw)I understand that you probably aren't in the postition to spend time on building these features for a tool that you are giving away for free. But may I suggest to consider a payed Business version with more advanced features.....?PS: In case you ever need to, you can contact me directly on MSNI put my MSN Live messenger address on my Sapiens forum account profile. Please do not send email to that address as I only use it for MSN.Thanx again for developing this super handy object!! It's a real life saver for all of us nostalgic vbscript veterans!!
sabofx2008-09-10 10:26:17
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

ActiveXPoSH syntax?

Post by jhicks »

Something isn't right when using the Eval method based on my testing as well using the Quest cmdlets. Using the Eval method for Get-Process returns true. But not for an expression like 'Get-QADuser Administrator'. Yet in the same script I can Execute it and get results. Executing Get-PSSnapin in my script shows the Quest snapin as loaded. But like your Exchange example, my cmdlet can't be evaluated.The dev team will have to look into this further.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

ActiveXPoSH syntax?

Post by Alexander Riedel »

Here is what eval does. Really simple, it takes your statement and wraps it like this:

$result = ("<YOUREXPRESSION>");
if($result) { "true"} else "false" }"

If there is a better way of doing this, I'd be more than happy to change it.
Alex
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

ActiveXPoSH syntax?

Post by jhicks »

Joost, What version of Windows Script Host are you running? 5.6 or 5.7?jeff
User avatar
sabofx
Posts: 10
Last visit: Tue Sep 29, 2015 3:24 pm

ActiveXPoSH syntax?

Post by sabofx »

Hi Jeff,I've been testing mainly on Windows Script Host Version 5.6 on Windows server 2003 enterprise SP2.Could this be related to the problem?Btw1: What version of powershell does activeposh use if powershell v2 ctp is installed?Btw2: Do you think there's is any chance that some of the features on my (updated!!) wish list will get implemented?Run PS commands on a remote machine(I have achieved something similar by combining ActiveXPosh with psexec (http://technet.microsoft.com/en-us/sysi ... px)Ability to use variables and/or objects from powershell in vbscript. For
example, ability to access an array that was created in PowerShell from vbscript.Launch ActiveXPosh object with alternate credentials (Usr/Pw)A new property ActiveXPosh.ExitCode. It could store the PowerShell exit code of the last ActiveXPosh.Execute command.More nfo on Powershell exit codes here -> http://blogs.msdn.com/powershell/archiv ... .aspxThanx again in advance!
sabofx2008-09-11 09:48:50
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

ActiveXPoSH syntax?

Post by jhicks »

I can't speak to the wish list other than I'm sure it will be looked at. If you Execute $host with ActiveXPOSH you should see something like this:Name : PrimalScriptHostImplementationVersion : 1.0.0.0InstanceId : e0bef306-1a1b-43ec-bac8-a1e461ea6751UI : System.Management.Automation.Internal.Host.InternalHostUserI nterfaceCurrentCulture : en-USCurrentUICulture : en-USPrivateData : IsRunspacePushed : Runspace : which indicates PowerShell v1.0. This is my output and I'm running the PowerShell CTP. But interestingly enough I don't have the problem. But I do on other systems running PowerShell v1.0 and WSH 5.6 or WSH 5.7. I've sent Alex some other information offline.
User avatar
sabofx
Posts: 10
Last visit: Tue Sep 29, 2015 3:24 pm

ActiveXPoSH syntax?

Post by sabofx »

Hi!My output executing $host from ActiveXPOSH:

D:>cscript m:test.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.Name : PrimalScriptHostImplementation
Version : 1.0.0.0
InstanceId : 3d680455-be2f-4ddd-95bb-86b6259b2d1a
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData :D:>




Not sure if this is relevant but I noticed the absence of values "IsRunspacePushed" and "Runspace" at the bottom. These seem to appear only on machines with wsh v5.7. (I checked on another machine)To fix the "objActiveXPosh.Eval" issue, I think it is a good idea if we both test with the same cmdlet. I propose to use /n software NetCmdlets V2You van download a free beta version from:http://www.nsoftware.com/download/downl ... type=exeTo reproduce the error, can you try to run this script (after installing the NetCmdlets):'-----------------------------------------------------------------------strPsCmdExample = "send-ping -server www.google.com"WScript.Echo GetOutputPowerShellCommand(strPsCmdExample)WScript.Echo EvalPowerShellCommand(strPsCmdExample)'===========================================================================' Evaluate command output for object returned as boolean'===========================================================================Function EvalPowerShellCommand(strPsCmd) Set objActiveXPosh = CreateObject("SAPIEN.ActiveXPoSH") success = objActiveXPosh.Init(vbTrue) EvalPowerShellCommand = objActiveXPosh.Eval(strPsCmd) Set objActiveXPosh = NothingEnd Function'==========================================================================' Return result output from Powershell command STRPSCMD on local machine' Value is returned as String'==========================================================================Function GetOutputPowerShellCommand(strPsCmd) 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 objActiveXPosh.OutputWidth = 200 objActiveXPosh.Execute(strPsCmd) GetOutputPowerShellCommand = objActiveXPosh.OutputString objActiveXPosh.ClearOutput() ' Empty the output buffer Set objActiveXPosh = NothingEnd Function'-----------------------------------------------------------------------On my machine the script output looks like this:C:Documents and SettingsAdm.kuin>cscript svbb001m$test.vbsMicrosoft (R) Windows Script Host Version 5.7Copyright (C) Microsoft Corporation. All rights reserved.Source Status------ ------66.249.91.103 OKsvbb001m$test.vbs(13, 5) System.Management.Automation: The term 'send-ping' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again.C:Documents and SettingsAdm.kuin>Can you run this on your own platform and analyse/post the output?
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

ActiveXPoSH syntax?

Post by jhicks »

I spent some time with Alex on this a little bit ago. He has some things to check out.
User avatar
sabofx
Posts: 10
Last visit: Tue Sep 29, 2015 3:24 pm

ActiveXPoSH syntax?

Post by sabofx »

He guys!Any progress? (or anything I can do?)Thanx,Joost!
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

ActiveXPoSH syntax?

Post by Alexander Riedel »

Currently testing a new version. A few more days.

Alex
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 14 years and 11 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.