|
Navigation: Actions > Miscellaneous > PowerShell > PowerShell Action Command Tab |
![]() ![]()
|
This tab of the PowerShell Action action configures information about the script to be run.
Command script: Specifies the script to invoke (required). The filename of a file can be provided, or the contents of a script can be entered in the second field.
Notes:
| • | Single parenthesis characters must be doubled (%%) to not be treated specially by Visual Build. Strings within parentheses (i.e., %PATH%) will also be expanded by Visual Build if not escaped. |
| • | Bracket characters [ and ] normally denote a script expression to be inserted into a field; to insert literal brackets, use two bracket characters [[ or ]]. |
| • | The exit code of the command processor will be stored in the RUNPROGRAM_EXITCODE temporary macro. |
| • | By default, PowerShell will not execute local unsigned scripts, and temporary script files created by this action are not signed. To enable PowerShell to execute local unsigned scripts, start PowerShell (running as admin) and enter the command Set-ExecutionPolicy RemoteSigned. Or sign your PowerShell scripts and specify the script filename above. |
Use the following code to read or write global macros from a PowerShell script (to transfer information between Visual Build and your script):
# create app object
$app = New-Object -com VisBuildSvr7.Application
# retrieve global macros
$global = $app.Macros(2)
# READ A VALUE FROM Visual Build
# Note: values can also be passed to the script via the Parameters field on the Input tab
# store a global macro value in a PowerShell variable
$val = $global.Item("ABC").Value
# echo the variable value (logged in Visual Build)
$val
# WRITE A VALUE TO Visual Build
# create/update macro with two values delimited by tab
$global.Add("XYZ", "val1`tval2")
# save changes to global macros (accessible in the following steps in Visual Build)
$global.Save()