Access FinalBuilder variables from PowerShell code

1.3k Views Asked by At

I added "Execute PowerShell Script" action to my FinalBuilder project. Manual says that I can access FinalBuilder variables using following syntax (entered in Specify Script area):

$FBVariables.GetVariable("VarName")

But the problem is $FBVariables in my case is always null, I mean following statement returns True:

$FBVariables -eq $null

I have no idea what I am doing wrong.

2

There are 2 best solutions below

1
On BEST ANSWER

$FBVariables is not available in the Execute PowerShell Script action.

You will have to use the Run Script ( or Execute Script in older versions I think) action, set language to Powershell in the Script Editor tab and here you can use #FBVariables

http://www.finalbuilder.com/Default.aspx?tabid=456&aft=9647#10952

0
On

Here is an example of a working PowerShell script contained in a LogVariables Action. I found you couldn't use the PowerShell Action with variables, so I just used another action and added a script to pass information in/out of Powershell Commandlets.

Powershell Script

Function ConvertNametoFolder([string]$FileName="VirtualServerInstanceName.web.config",    [string]$FileSuffix="web.config")
{
   [string]$Result = ""
   if ($FileLen -ne "")
   {
      [int]$FileLen = $FileName.Length
      [int]$SuffixLen = $FileSuffix.Length
      $Result = $FileName

      $Result = $FileName.SubString(0,($FileLen-$SuffixLen)-1)

      # String join method (not safe)
      #$Result =  $Result + "\" + $FileSuffix

      # .net Framework safe method for combining folder\file paths to Windows Standards.
      $Result = [System.IO.Path]::Combine($Result, $FileSuffix)
    }
Return $Result
}

$FileIn = $FBVariables.GetVariable("varWebConfigFilePath") # Passed-in at runtime
[string]$PathOut =  ConvertNametoFolder $FileIn
$FBVariables.GetVariable("varIisSettingFile")
$FBVariables.SetVariable("varWebConfigFileDestinationPath", $PathOut)