ActionScript multiline

Hello

I am new to BigFix and trying to find a cleaner way of doing things.

I have a long, multiline powershell command i need to push to clients

writing it in 1 long line works well

however, i like it a little more human readable and cleaner :slight_smile:

so, i have been trying to either:

  • create a parameter and keep adding the ‘new lines’ to it (really just creating 1 long command inside the parameter) or
  • be able to create a multiline command inside the action scripts window.

i have not bee successful with either. Syntax from other languages do not work here (such as myVarable += “my additional text”)

here is a sample of what i have (this sample is supposed to create a scheduled task on client):

parameter “myCmd” = “$taskAction = New-ScheduledTaskAction” &
parameter “myCmd” = {parameter “myCmd”} & " -Execute ‘c:\temp\Deploy.cmd’"
parameter “myCmd” = {parameter “myCmd”} & " -WorkingDirectory ‘C:\users\Public’"
parameter “myCmd” = {parameter “myCmd”} & "; $trigger = New-ScheduledTaskTrigger"
parameter “myCmd” = {parameter “myCmd”} & " -Once"
parameter “myCmd” = {parameter “myCmd”} & " -At 10pm"
parameter “myCmd” = {parameter “myCmd”} & "; $settings = New-ScheduledTaskSettingsSet"
parameter “myCmd” = {parameter “myCmd”} & " -StartWhenAvailable"
parameter “myCmd” = {parameter “myCmd”} & " -RunOnlyIfIdle"
parameter “myCmd” = {parameter “myCmd”} & " -WakeToRun"
parameter “myCmd” = {parameter “myCmd”} & "; Register-ScheduledTask"
parameter “myCmd” = {parameter “myCmd”} & " -Action $taskAction"
parameter “myCmd” = {parameter “myCmd”} & " -Settings $settings"
parameter “myCmd” = {parameter “myCmd”} & " -Trigger $trigger"
parameter “myCmd” = {parameter “myCmd”} & " -TaskName ‘TestDeploy’"
parameter “myCmd” = {parameter “myCmd”} & " -Description ‘Run Once to deploy’"
parameter “myCmd” = {parameter “myCmd”} & " -User ‘SYSTEM’“
parameter “myCmd” = {parameter “myCmd”} & " -RunLevel Highest"
parameter “myCmd” = {parameter “myCmd”} & " -AsJob”

run powershell.exe -ExecutionPolicy Bypass -Command {parameter “myCmd”}

First of all, welcome to BigFix! We have a number of resources to help you learn, including the Relevance Guide, ActionScript Guide, and References over at https://developer.bigfix.com.
We also have formal, live training sessions for which you could consider registering, detailed at NEW BigFix Enablement Website is LIVE!, and our BigFix Tech Advisors YouTube channel with specific solutions at https://www.youtube.com/channel/UCtoLTyln5per0JYzw1phGiQ/featured . Check the “Playlists” there and you can watch a recording of a past session of the BigFix Foundations Training which might be helpful.

Now, to solve your problem, you are probably already observing that once we create and set a value for a parameter in ActionScript, we cannot change or append to that parameter later. Parameters are write-once.

To handle a multiple PowerShell script, we’d use the ‘createfile’ or ‘appendfile’ commands to build a PowerShell script on-the-fly, move the generated file to a PowerShell script (.ps1), and use the ‘wait’ or ‘run’ commands to execute the PowerShell script.
PowerShell scripts often have embedded { } symbols, so be sure to escape each open curly-bracket by replacing it with two open curly-brackets, otherwise BigFix would interpret that as the start of a Relevance Substitution.

I have a template that I like to use for PowerShell scripts, that handles running non-Interactive, and saving the script output to a file. You should be able to replace the PowerShell portion of this with your script (again, escaping { as {{ to prevent unwanted Relevance Substitutions)

delete __createfile
// Create a file until the EOF_EOF_EOF_EOF marker
// Ensure any { symbols are escaped as {{ to prevent relevance substitutions
createfile until EOF_EOF_EOF_EOF
Get-WinEvent -FilterHashtable @{{
   LogName='System'
   ProviderName='*schannel'
}
EOF_EOF_EOF_EOF
// Move the generated __createfile to GeneratedScript.ps1
delete GeneratedScript.ps1
move __createfile GeneratedScript.ps1

// Ensure the PowerShell script runs in 64-bit mode
action uses wow64 redirection false

// Execute the PowerShell script; wrapping it in a cmd.exe to handle output redirection.
wait cmd.exe /c "PowerShell.exe -NonInteractive -ExecutionPolicy Bypass -File GeneratedScript.ps1 > "ScriptOutput.txt" 2>&1"
2 Likes

Hello Jason.

Thank you very much for the wealth of training material…it will come in handy!

…Write-once… yeah - that will do it and explains my headaches over the weekend :slight_smile:

i had found the write to file approach over the weekend on Dr. Google… but was still thinking about a variable/parameter fill approach.

I’ll give your template a try a little later today and post back my success. this would be sufficient for my current task.
What if its a large .ps1 file… currently i can only think about 2 separate task, 1st copy the file to the machine, 2nd execute if file exist… sounds about right?

Thanks for all your help

Sure, if you have a prebuilt PowerShell script you could download it to the client and then run it, but this method should still work at least up to several KB of script.

1 Like