Ask Your Question

How to script powershell exit codes so that puppet knows when a script fails?

asked 2013-01-23 14:52:29 -0500

Michael Thompson gravatar image

updated 2013-01-24 10:20:40 -0500

llowder gravatar image

Puppet and Powershell exit codes

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2013-01-24 07:28:32 -0500

Michael Thompson gravatar image

Solution: To get puppet to see the exit code of a powershell script you need to run the script with the -Command switch. See the following Link:


exec { "powershell-test": command => 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -executionpolicy remotesigned -Command C:/NSM/SCRIPTS/psget.ps1', #path => "/usr/bin:/usr/sbin:/bin:/usr/local/bin", #refreshonly => true, }

edit flag offensive delete link more



To target Windows 64-bit you need to add sysnative

exec { "powershell-test": command => 'C:/Windows/sysnative/WindowsPowerShell/v1.0/powershell.exe -executionpolicy remotesigned -Command C:/NSM/SCRIPTS/psget.ps1', #path => "/usr ...(more)

louis gravatar imagelouis ( 2013-02-06 21:02:27 -0500 )edit

answered 2013-04-13 14:48:17 -0500

the exit command in powershell can control what exit code you want to return. This can be helpful in simply returning a 1 or 0, for instance depending on a powershell conditional.

edit flag offensive delete link more

answered 2013-01-23 17:21:01 -0500

Puppet handles Powershell scripts the same way it handles other executable commands, which is that an exit status of 0 is considered to be success and a non-zero exit status will be treated as a failed resource.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-01-23 14:52:29 -0500

Seen: 1,426 times

Last updated: Apr 13 '13