The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

  • Archives

  • Meta

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

Posted by Mikael Nystrom on June 15, 2015

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

One Response to “PowerShell Is King – Run a EXE inside with style and exit code control”

  1. Hi Mikael,
    This post helped me the create other scripts custom for my environment and labs.
    Great post

    Thank you.

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

 
%d bloggers like this: