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.
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.
Example: ping 127.0.0.1 with the expected exit code of 10 which will NOT be returned
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
This post helped me the create other scripts custom for my environment and labs.