I am trying to invoke a PowerShell script from Puppet. The issue is even if the PowerShell script fails on remote box, it still shows successful run as shown below:
Notice: /Stage[main]/Main/Node[dev.abc.com]/Exec[Check UAC]/returns: executed successfully
Content of my node block in site.pp
:
exec { 'Check UAC':
command => '& C:\temp\check_uac.ps1',
provider => powershell,
logoutput => 'on_failure',
}
The script failed when I tried running from PowerShell console stating that execution policy was set to Restricted.
PS C:\> C:\temp\check_uac.ps1 C:\temp\check_uac.ps1 : File C:\temp\check_uac.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1 + C:\temp\check_uac.ps1 + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess
How can I capture the above error when invoking the script from Puppet to avoid surprises later?