VSoft Technologies Blogs

rss

VSoft Technologies Blogs - posts about our products and software development.

Introduction

PowerShell support in FinalBuilder 5.5 was limited to the Execute PowerShell Action. For FinalBuilder 6, we've made PowerShell a "first class" scripting language, alongside JavaScript and VBScript.

This is the first in a series of blog posts which show the different ways PowerShell can integrate with FinalBuilder. Today's example is the Execute Condition.

Execute Conditions

Every action in FinalBuilder has a field called the "Execute Condition", on the Runtime property page.

This lets you place a single line of script which evaluates as a boolean condition. If the script evaluates "True", the action will execute. If the script evaluates "False", the action will be skipped.

PowerShell Execute Conditions

Due to it's terse but expressive syntax, PowerShell seems to lend itself to one-line expressions (a quick Google search will confirm this.) This can be great for execute conditions.

Examples

If you want an action to only run if Notepad is executing, you can use this one-line expression:

get-Process | where {$_.name -eq "NotePad"}

PowerShell Execute Condition

If you want an action to run only if a remote computer is online, you can use this expression:

gwmi Win32_PingStatus -Filter "Address='remotePC'" |where {$_.StatusCode -eq 0}

PowerShell treats any non-null value as equivalent to $True, so any result will be regarded as True, while no result will be regarded as False.

Caveats

I think one-liners are neat. It's probably because they remind me of growing up with my Apple //e and Nibble magazine's one-liner competition. However, like anything else, one liners can be abused. They can be the stuff of programming horror stories.

My suggestions for responsible Execute Condition use:

  • Put something in the action comment field if the Execute Condition isn't self-documenting.
  • Use a script event if the Execute Condition gets longer than the text field on the Runtime page.

 

Next - Part Two : Script Events

 

( Credits : thanks to beta tester Robert for the Notepad suggestion.)

Showing 1 Comment

Avatar
rlove 16 years ago

Glad to see this blog post ;-)



Comments are closed.