This is a good resource for PowerShell and its interesting behaviors:
http://zduck.com/2012/powershell-batch-files-exit-codes/

Also, have you looked at http://forge.puppetlabs.com/joshcooper/powershell


On Wed, Feb 5, 2014 at 8:36 PM, Leon Kyneur <[email protected]> wrote:

> Hi,
>
> I have a powershell script which I'm trying to implement within an
> exec/onlyif condition.
>
> The script I'm working with is quite complex so I don't really want to put
> all of the logic inline and would prefer it stayed contained within the
> .ps1. I'm running into issues calling powershell and returning an exit code.
>
> For example my .ps1 file has a statement like this:
>
> If (condition) {
>   # run exec command =>
>   exit 1
> } else {
>   # don't run exec command =>
>   exit 0
> }
>
> In my exec I have a command structured like so:
>
> exec { "run-script":
>   path =>  'C:\Windows\sysnative\WindowsPowershell\v1.0',
>   command => "powershell.exe -File C:/myscript.ps1 arg1 arg2",
>   onlyif => "powershell.exe -File C:/myscript.ps1 -runcheck",
> }
>
> Regardless of the condition / exit code within the script the command
> portion always runs always runs. I've tried to switch out -File for
> -Command without success.
>
> Can anyone point out a way around this?
>
> Regards,
>
> Leon
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/CAPnT6nN51aUYOSBTYzD6M-X9768pG2WwE6vXzQnJGNNATR7cgw%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Rob Reynolds
Developer, Puppet Labs

*Join us at PuppetConf 2014, September 23-24 in San Francisco - *
http://bit.ly/pupconf14

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAMJiBK5B9LeDSTLhMeqPEu8teswusDAQhr53_sAuMfitbR%3DcSw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to