Invoking PowerShell from VBScript (COM)

Invoking PowerShell from VBScript (COM)

  • Comments 4

There are a number of scenarios where you might want to call PowerShell from VBScript. 

  • You might already have an VBScript that does some function and you want to update it to include some PowerShell operation but don't want to convert the entire script to PowerShell. 
  • You might have some people on your staff that are very comfortable with VBScipt and aren't ready to put it down and do everything in PowerShell. 
  • You might have a management tool that is hardwired to invoke VBScripts and doesn't know anything about PowerShell (yet!).

These are some of the scenarios we thought about when we considered providing a COM interface to the PowerShell engine.  To ship is to choose and this scenario got a lower priority than other features so we never got around to it.  Luckily, the superstars at Sapien have come to the rescue with ActiveXPosh .   ActiveXPosh is a COM component which gives you easy access to PowerShell from any COM capable scripting language (VBScript, JScript and others).   This has been out for a while but it came out during a period when my hair was on fire so I don't recall seeing it.  There is a good description of its capabilities HERE.

With ActiveXPosh you can do things like:

Set ActiveXPosh = CreateObject("SAPIEN.ActiveXPosh")
if ActiveXPosh.Eval("Get-Process Winword") = vbTrue Then
     WScript.Echo "Word is running"
Else
     WScript.Echo "Word is NOT running"
End If

Pretty simple stuff!  So - how could it get any better?  Yup - you guessed it, ActiveXPosh is FREE.  Is this a wonderful world or what?

Thank you SAPIEN!

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Leave a Comment
  • Please add 5 and 2 and type the answer here:
  • Post
  • Hi,

    I tried to install it on Windows Vista 64 bit, the installation passed successfully, without any error message, but it doesn't work. none of the sample works.... anyone know why?

    thanks,

    Shahar.

  • I don't have access to a 64-bit system.  I understand that PowerShell is installed basically twice on 64-bit systems.  You may need to invoke the 32-bit version one to use this add-on.

  • We have a support forum for our free tools at http://support.sapien.com

    If you have any trouble with this, please post there.

    Thanks.

    Alexander Riedel

    SAPIEN Technologies, Inc.

    alexr@sapien.com

  • Another reason for not using Powerpoint is that is has no proper debugger, with vbscript I can use visual studio to write and debug scripts interactively in a nice gui environment, some of which can run to thousands of lines. I would not like to write anything more than 20 or thirty lines in powershell as I would be hard to maintain.

    Powershell seems to be in a world of it's own and does not seem to fit into the rest of microsofts development environment, it's as if it were written by a seperate company.

Page 1 of 1 (4 items)