# Use script in only\_if and not\_if

**URL:** <https://discourse.chef.io/t/use-script-in-only-if-and-not-if/15546>\
**Category:** Chef Infra (archive)\
**Created:** [July 9, 2019, 9:53am UTC](https://discourse.chef.io/t/use-script-in-only-if-and-not-if/15546 "2019-07-09T09:53:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rishabh](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@rishabh](https://discourse.chef.io/u/rishabh)\
**Post date:** [July 9, 2019, 9:53am UTC](https://discourse.chef.io/t/use-script-in-only-if-and-not-if/15546/1 "2019-07-09T09:53:51Z")

</div>

I want to use powershell script in only\_if and not\_if in one of my resource. Please help me in using that.

---

<div class="post-metadata">

**Author:** ![stuartpreston](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/stuartpreston/32/1771_2.png) [@stuartpreston](https://discourse.chef.io/u/stuartpreston)\
**Post date:** [July 9, 2019, 10:14am UTC](https://discourse.chef.io/t/use-script-in-only-if-and-not-if/15546/2 "2019-07-09T10:14:36Z")

</div>

PowerShell script is the default guard interpreter for the powershell\_script resource. If you want to use it with other resources add the following to your resource:

```auto
guard_interpreter :powershell_script

```

Then you can follow the same guidance for using Guards in the powershell\_script resource as per [https://docs.chef.io/resource\_reference.html#id565](https://docs.chef.io/resource_reference.html#id565)

Contrived example:

```auto
your_resource 'your_resource_name' do
  a_resource_property 'first'
  guard_interpreter :powershell_script
  not_if 'Test-Path c:\' # will return $True
end

```

---

<div class="post-metadata">

**Author:** ![rishabh](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@rishabh](https://discourse.chef.io/u/rishabh)\
**Post date:** [July 9, 2019, 10:24am UTC](https://discourse.chef.io/t/use-script-in-only-if-and-not-if/15546/3 "2019-07-09T10:24:37Z")

</div>

@stuartpreston  
I want to use a multi-line script like file.ps1 which will return true or false. I want to evaluate based on that.

**your\_resource 'your\_resource\_name' do  
a\_resource\_property 'first'  
guard\_interpreter :powershell\_script  
not\_if file.ps1  
end**

---

<div class="post-metadata">

**Author:** ![stuartpreston](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/stuartpreston/32/1771_2.png) [@stuartpreston](https://discourse.chef.io/u/stuartpreston)\
**Post date:** [July 9, 2019, 2:05pm UTC](https://discourse.chef.io/t/use-script-in-only-if-and-not-if/15546/4 "2019-07-09T14:05:47Z")

</div>

Having a multi-line script as a guard is usually a "smell" that you might be able to break down the work a bit more into multiple resources within your recipe. But if you must then you can use the **powershell\_out** Ruby mixin to achieve this, example:

test.ps1:

```auto
($true -eq $true)

```

recipe.rb:

```auto
log 'testing' do
  not_if { powershell_out('test.ps1') }
end

```
