Welcome to MSDN Blogs Sign in | Join | Help

Invoking PowerShell from VBScript (COM)

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

Published Friday, July 25, 2008 4:44 PM by PowerShellTeam
Filed under: , , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Invoking PowerShell from VBScript (COM)

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.

Saturday, July 26, 2008 3:01 PM by Shahar Gvirtz

# @ 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.

Monday, July 28, 2008 9:46 AM by Marco Shaw

# re: Invoking PowerShell from VBScript (COM)

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

Monday, July 28, 2008 1:22 PM by Alexander Riedel

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker