Skip to content

Instantly share code, notes, and snippets.



Created May 31, 2012
What would you like to do?
PowerShell Exec function from psake
# Taken from psake
This is a helper function that runs a scriptblock and checks the PS variable $lastexitcode
to see if an error occcured. If an error is detected then an exception is thrown.
This function allows you to run command-line programs without having to
explicitly check the $lastexitcode variable.
exec { svn info $repository_trunk } "Error executing SVN. Please verify SVN command-line client is installed"
function Exec
[Parameter(Position=1,Mandatory=0)][string]$errorMessage = ($msgs.error_bad_command -f $cmd)
& $cmd
if ($lastexitcode -ne 0) {
throw ("Exec: " + $errorMessage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment