Thanks Rob. I'm well aware of both resources you mentioned but neither have
provided me with a valid solution to my problem.

The powershell provider works well if I place my code inline within the
manifest.

However the script I'm working with had a lot of logic. I don't see it
being very maintainable all mashed up together inline in my onlyif
statement.

Even following the all suggestions from the article on exit codes I cannot
clearly see why puppet doesn't get the correct exit code when called from
within the ps1 file.
On Feb 6, 2014 4:52 PM, "Rob Reynolds" <[email protected]> wrote:

> 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.
>

-- 
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/CAPnT6nOETQK9CXU6pLjG2juc5sZz%3DxRazJqeJpAxZC05YL1sxg%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to