Need help running Powershell script via fixlet

Hello All

I need some advise on running Powershell script as part of software distribution on a Windows Server .
The package copied successfully and the fixlet executed successfully with exit code 0 but the software didn’t install.
Command Line : wait cmd.exe /c powershell -file “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\actionsite__Download\MHAS-Monitoring-Install-Script.ps1”

Request you to help me with issues on powershell parameters .

Thank you
Vish

Hi,

Try below script:-

//PowerShell Script…
//
//1. Save old ExecutionPolicy value
parameter “PolicyExisted”="{exists value “ExecutionPolicy” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell” of (if exists x64 registry then x64 registry else registry)}“
parameter “oldExecutionPolicy”=”{if (parameter “PolicyExisted” as boolean) then (value “ExecutionPolicy” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell” of (if exists x64 registry then x64 registry else registry) as string) else “”}"
//2. set to ExecutionPolicy=Unrestricted and Pull PowerShell exe from registry… if 64bit then pull PowerShell x64
if {x64 of operating system}
regset64 “[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]” “ExecutionPolicy”=“Unrestricted"
parameter “PowerShellexe”=”{value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell” of x64 registry}"
else
//we need to determine what the current execution policy is so we can put it back when we’re done.
regset “[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]” “ExecutionPolicy”=“Unrestricted"
parameter “PowerShellexe”=”{value “Path” of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell” of registry}"
endif
//3. Create PowerShell script and save to a ps1 file
delete __appendfile
delete script.ps1
appendfile get-help | Out-File $env:temp\script.log
move __appendfile script.ps1
//4. Execute PowerShell with ps1 script file
action uses wow64 redirection false
waithidden “{parameter “PowerShellexe”}” -file “C:\powershellscriptFile.ps1"
action uses wow64 redirection {x64 of operating system}
//5. Restore ExecutionPolicy back
if {x64 of operating system}
if {parameter “PolicyExisted” as boolean}
regset64 “[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]” “ExecutionPolicy”=”{parameter “oldExecutionPolicy”}"
else
regdelete64 “[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]” “ExecutionPolicy"
endif
else
if {parameter “PolicyExisted” as boolean}
regset “[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]” “ExecutionPolicy”=”{parameter “oldExecutionPolicy”}"
else
regdelete “[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]” "ExecutionPolicy"
endif

Let me know if it works

I think you can just add -Executionpolicy Bypass on the powershell command line?

@JasonWalker
Thank you for your reply.

I have run set-Executionpolicy Bypass on the end point manually and tried to trigger the command line again on the end point via fixlet debugger. However, I get a diff error this time

Command line
wait cmd.exe /k powershell -file “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\actionsite__Download\MHAS-Monitoring-Install-Script.ps1” passive6east 158.87.44.155

Error |

File C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\actionsite_
_Download\MHAS-Monitoring-Install-Script.ps1 cannot be loaded because the execu
tion of scripts is disabled on this system. Please see “get-help about_signing”

@JasonWalker
Thank you for your suggestion , I worked by adding -ExecutionPolicy Bypass

Thank you so much