Run: PowerShell Script - Windows - TEMPLATE
Log In or Register to download the BES file, and more.

2 Votes

Versioning - This is the latest version.

1PowerShell Template Task10/24/2012 1:43:56 PM
2Run: PowerShell Script - Windows - TEMPLATE9/22/2014 12:51:23 PM

Description

Template to run a powershell script

 

References:

http://bigfix.me/fixlet/details/633

 


Property Details

ID3860
StatusAlpha - Code that was just developed
TitleRun: PowerShell Script - Windows - TEMPLATE
DomainBESC
Download Size0
SourceInternal
Source IDjgs194
Source Release Date9/22/2014 12:00:00 AM
KeywordsPowerShell
Is TaskTrue
Added by on 9/22/2014 12:51:23 PM
Last Modified by on 9/22/2014 12:51:23 PM
Counters 23458 Views / 214 Downloads
User Rating 1 star 2 star 3 star 4 star 5 star * Average over 3 ratings. ** Log In or Register to add your rating.

Relevance

Windows Only (Relevance 2997197)
Used in 6448 fixlets and 32 analyses   * Results in a true/false
Show indented relevance
/* Windows Only */ windows of operating system
Used in 158 fixlets and 17 analyses   * Results in a true/false
Show indented relevance
/* Windows XP or Higher */ version of operating system >= "5.1"
Used in 3 fixlets   * Results in a true/false
Show indented relevance
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:
Share this page on Yammer

Comments

Log In or Register to leave comments!
jgstew -
please create a post on forum.bigfix.com and CC @jgstew and provide a link to this to get help.
shiva.kalal -
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.
shiva.kalal -
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.
cmenard -
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.
DanPaquette -
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"
Avi -
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!
danielheth -
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.
Avi -
i could not make it work with runascurrentuser.exe from bes support, do you know of a way to make it work?
neonbluefire -
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/
danielheth -
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.
dmoore -
Is the line {parameter "PowerShellexe"} supposed to read that way, or is it supposed to read PowerShell.exe?