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"
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
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?
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.