PowerShell condition in non powershell_script blocks

How can i use PowerShell commands as an ‘only_if’ ‘not_if’ condition in a non powershell Chef resource?
Is i possible?

For example :

package 'Application X' do
  source "#{Chef::Config['file_cache_path']}\App\Setup.exe"
  installer_type :custom
  action :install
  returns [0, 3010]
   not_if 
  	powershell_script
    	code <<-EOH
   	$file_version = (Get-Item E:\App\App\appx.exe).VersionInfo.FileVersion
   	$file_version != node['app']['version']
   	EOH
  	end
  end

Many thanks for taking a look - hopefully its simple

Edit : continuing my searches I found shell-out or Mixlib::ShellOut.new - not sure if those are relevent to this

I believe you are looking for the guard_interpreter attribute. See https://docs.chef.io/resource_common.html#guard-interpreters. By setting the guard_interpreter attribute to :powershell_script you can use powershell in your only_if and not_if conditions.

Hi Matt,

“guard_interpreter :powershell_script” works and causes that block of code in the ‘not_if’ to execute PowerShell.

Many thanks

Dave