Ask Your Question
2

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
1

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: http://chuchuva.com/pavel/2012/05/powershell-exit-codes/

Example:

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

Comments

1

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
0

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
0

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

Your Answer

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

Add Answer

Question Tools

Stats

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

Seen: 1,547 times

Last updated: Apr 13 '13