PowerShell

PowerShell Is King – Run a EXE inside with style and exit code control

So, in reality there is many ways to do this, but this is the method I have found to be the most reliable and it gives me the functions I need. It runs it, it waits, returns the return code and if the does not match it fails. The script is based on bits and pieces found in different location on the Internet, thinking and working.

image

It is created as a function, that way you can drop it directly into your script and just it.

Example: Ping 127.0.0.1 with the expected exit code of 0 should returned.

image

Example: ping 127.0.0.1 with the expected exit code of 10 which will NOT be returned

image

I use this module in basically every new script I create, there is always an exe that needs to run…

You can download the snippet here. http://1drv.ms/1bwlwXm

/mike

Categories: PowerShell

Tagged as:

1 reply »

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.