Embedded VBScript Console Task

The other day I needed a Console task to run a vbscript for checking some stuff concerning an application. I wanted to  embed the script into the management pack I put together so that it would be available to everyone. To my surprise this couldn’t be done, it’s only possible to execute a single command (with some arguments) when authoring a Console Task.

 After experimenting a bit I found a way to get around this limitation, hopefully this is useful for you as well.

 

Create a new Command Line Task from the Authoring section of the OpsMgr console.

 

Enter a name and target.

Now here comes the tricky bit.

In the Application box enter: %comspec%

In the Parameters box enter the following:

/c echo wscript.echo “This is the first script line” > EmbeddedVBScript.vbs && echo wscript.echo “This is the second script line” >> EmbeddedVBScript.vbs && EmbeddedVBScript.vbs

The above command line will output a small VBScript and execute it:


wscript.echo "This is the first script line"
wscript.echo "This is the second script line"

Basically what we do is echo the VBScript code into a file called EmbeddedVBScript.vbs. We separate the echoed lines by using the && command, this causes %comspec% to start a new line. At the end we execute the EmbededVBScript.vbs.

A few notes:

If you are going to use this method you are limited to about 8000 characters, if you try to use more your script will be incomplete.

You might need to start the OpsMgr console with elevated privileges if your working directory is located somewhere in Program Files.

This is the output:

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s