Getting a failure in a powershell job to fail the Travis CI job

We are doing powershell -ExecutionPolicy RemoteSigned -File .travis.ps1 which works as expected but maybe it works too well. If there is a failure in the powershell script, that error does not get returned back to Travis. We would like the Travis job to fail if the powershell script fails but we have not found a way to make that happen.

Answer: In a .ps1 fileā€¦

    try { 
	java -version
    } catch { 
	echo "java -version failed"
	exit 1