Run: PowerShell Script - Windows - TEMPLATE
4 Votes |
Versioning - This is the latest version.
1 | PowerShell Template Task | 10/24/2012 1:43:56 PM |
2 | Run: PowerShell Script - Windows - TEMPLATE | 9/22/2014 12:51:23 PM |
Description
Template to run a powershell script
References:
http://bigfix.me/fixlet/details/633
Property Details
3860 | |
Alpha - Code that was just developed | |
Run: PowerShell Script - Windows - TEMPLATE | |
BESC | |
0 | |
Internal | |
jgs194 | |
9/22/2014 12:00:00 AM | |
PowerShell | |
True | |
jgstew on 9/22/2014 12:51:23 PM | |
jgstew on 9/22/2014 12:51:23 PM | |
54355 Views / 497 Downloads | |
![]() ![]() ![]() ![]() ![]() |
Relevance
Windows Only (Relevance 2997197)

/* Windows Only */ windows of operating system

/* Windows XP or Higher */ version of operating system >= "5.1"
Used in 3 fixlets | * Results in a true/false |

exists file ((it as string) of value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of native registry)
Actions
Action 1 (default)
Action Link Click
here to deploy this action.
Script Type
BigFix Action Script
// Disable wow64 redirection on x64 OSes
action uses wow64 redirection {not x64 of operating system}
delete __createfile
// CREATEFILE
createfile until END_OF_FILE
# REPLACE THE FOLLOWING WITH THE SCRIPT YOU WANT TO RUN ON THE ENDPOINT
get-help | Out-File "{(pathname of folder "__BESData\__Global\Logs" of parent folder of client)}\config_powershell.log"
END_OF_FILE
delete powershell.ps1
move __createfile powershell.ps1
waithidden { pathname of file ((it as string) of value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of native registry) } -ExecutionPolicy Bypass -File powershell.ps1
Success Criteria
This action will be considered successful when the applicability relevance evaluates to false.
Sharing
Social Media: |
Comments
![]() |
|
I am trying to add below set of command using template however it is failing . Command failed (substitution failed while writing file) $Adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DHCPEnabled -ne 'True' -and $_.DNSServerSearchOrder -ne $null} $Adapters | ForEach-Object {$_.DNSServerSearchOrder} $NewDnsServerSearchOrder = "192.168.1.13","192.168.1.14" $Adapters | ForEach-Object {$_.SetDNSServerSearchOrder($NewDnsServerSearchOrder)} | Out-Null |
![]() |
|
Just tested this to help out with a forum posting. Currently working on Windows Server 2016 x64 - BigFix 9.5.14.73 |
![]() |
|
please create a post on forum.bigfix.com and CC @jgstew and provide a link to this to get help. |
![]() |
|
This script is not working, I have tried copy pasting this and applied to a test server. it is not working getting status as failed. |
![]() |
|
This script in not working, I have tried copy pasting this and applied to a test server. it is not working getting status as failed. |
![]() |
|
I would suggest moving "//2. set to ExecutionPolicy=Unrestricted...." after "//3. Create PowerShell script and save to a ps1 file". If you have a failure with appendfile or createfile, you will have set the executionpolicy and the action will not set it back. |
![]() |
|
Just wondering... We are instead creating this script via createfile. $objUser = New-Object System.Security.Principal.NTAccount("ikon1", "svc-zenosswmi") $strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]) $strSID.Value Think we have a syntax error in this line: waithidden "{parameter "PowerShellexe"}" -file "{pathname of client folder of current site}\script.ps1 | Export-Csv c:\test.txt" |
![]() |
|
Hi Daniel, Thanks! also how does one keep tracks of the versions that are available for "runascurrentuser.exe" ? Tried with the newer version and it was successful after fixing relevance etc. the part with looks like this when it works (i didn't need the wait since i tested it): run "__Download\RunAsCurrentUser-2.0.3.1.exe" --q "{parameter "PowerShellexe"}" -file "script.ps1" good job! |
![]() |
|
I've never tried doing that... but you might consider looking at this task (http://bigfix.me/cdb/fixlet/678). It is an example of using the "current user" utility (RunAsCurrentUser-2.0.3.1.exe) provided by corp. |
![]() |
|
i could not make it work with runascurrentuser.exe from bes support, do you know of a way to make it work? |
![]() |
|
For within the actual powershell script to return actual exit codes we had to do the following with the [Environment]::Exit("#");: { ## - Custom Exit Code: [Environment]::Exit("99"); } If you did not do this the exit code would be 1 every time. Found this here: http://www.maxtblog.com/2011/09/creating-your-own-exitcode-in-powershell-and-use-it-in-ssis-package/ |
![]() |
|
It is a variable name... I have rather descriptive variables and like to keep them simple, so I left out the period. The variable actually points to the full path to the powershell.exe and makes it easy so I can pull its location from the registry only once. |
![]() |
|
Is the line {parameter "PowerShellexe"} supposed to read that way, or is it supposed to read PowerShell.exe? |