Skip to content

Invoke COM method in Powershell

December 12, 2011

Today I was writing a script that would execute all SQL scripts in some folder and for that I needed to connect to the database. Where I work, we have a COM wrapped VBscript that gives Connection String and that is what I needed.

So lets see how to get it in Powershell:

First we need an wsc script containing data

<package id="config">
 <script language="VBScript">
   Function GetDBConnectionString()
     GetDBConnectionString = "connectionStringOfMike"
   End Function
<registration description="MikesConfig"

 <method name="GetDBConnectionString" dispid="1"/>

and now to get it in Powershell, just execute this:

$config = New-Object -com config.wsc
$DBConnectionString =

and you have a connection string generated by your COM method.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: