# Execute Condition using PowerShell

**URL:** <https://www.finalbuilder.com/forums/t/execute-condition-using-powershell/6692>\
**Category:** Discussion\
**Created:** [January 13, 2020, 8:16pm UTC](https://www.finalbuilder.com/forums/t/execute-condition-using-powershell/6692 "2020-01-13T20:16:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomas.lundstrom](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/t/a5b964/32.png) [@tomas.lundstrom](https://www.finalbuilder.com/forums/u/tomas.lundstrom)\
**Post date:** [January 13, 2020, 8:16pm UTC](https://www.finalbuilder.com/forums/t/execute-condition-using-powershell/6692/1 "2020-01-13T20:16:57Z")

</div>

Hi, I want to check for the existence of a folder before running a build step.  
I added a simple:  
Test-Path ‘C:\some\path’ which of course works as expected in a PowerShell.

However, in FinalBuilder 8, the condition always evaluates to True, regardless of the path provided.

Any Ideas?

Cheers,  
Tomas

---

<div class="post-metadata">

**Author:** ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)\
**Post date:** [January 14, 2020, 4:58am UTC](https://www.finalbuilder.com/forums/t/execute-condition-using-powershell/6692/2 "2020-01-14T04:58:38Z")

</div>

Hi Thomas

It’s a bug. I’m not sure when this started happening, but the powershell api was returning a different object to what we were previously expecting. This build has the fix

[https://downloads.finalbuilder.com/downloads/finalbuilder/800/FB800\_2791.exe](https://downloads.finalbuilder.com/downloads/finalbuilder/800/FB800_2791.exe)

Note that another option is the If File/Folder Exists action.

[https://wiki.finalbuilder.com/display/FB8/Check+If+File+or+Folder+Exists+Action](https://wiki.finalbuilder.com/display/FB8/Check+If+File+or+Folder+Exists+Action)

---

<div class="post-metadata">

**Author:** ![tomas.lundstrom](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/t/a5b964/32.png) [@tomas.lundstrom](https://www.finalbuilder.com/forums/u/tomas.lundstrom)\
**Post date:** [January 29, 2020, 8:22pm UTC](https://www.finalbuilder.com/forums/t/execute-condition-using-powershell/6692/3 "2020-01-29T20:22:00Z")

</div>

Hi, I tried 2791.  
It works for hard-coded string paths, like ‘Test-Path C:\Windows’  
But if I use a variable, like ‘Test-Path %SOME\_VALID\_PATH%’ it always fails.

I also tried the File/Folder Exists option, but that one has other problems.  
If I want to set a variable with the result of the operation, the dropdown only shows non-macro variables. But that’s pretty useless. I must of course use a macro variable that is recalculated later.

---

<div class="post-metadata">

**Author:** ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)\
**Post date:** [January 29, 2020, 10:20pm UTC](https://www.finalbuilder.com/forums/t/execute-condition-using-powershell/6692/4 "2020-01-29T22:20:37Z")

</div>

You can’t reference variables using % in scripts. In powershell you would use

```powershell
Test-Path $FBVariables["SOME_VALID_PATH"]

```

As for the File/Folder Exists action - you cannot set macro variables anywhere in FinalBuilder by design. Their value is based on their default value expression, which is evaluated every time the variable is accessed.
