Powershell Script run Issue

Team, i have tried to run a sample powershell script by calling powershell.exe and also using

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 “C:\Temp\powershell.ps1”. But both of the cases i am unable to run that sample script powershell.ps1. Please help me.

I evan copied powershell.exe on that location and put that in to temp folder. But not working but if i run manually, it is running.

1 Like

Take a look at the folowing post on the same subject: Run Powershell Script with BigFix

1 Like

Hello FDA, tried all the steps but still no luck.

have you tried doing waithidden cmd.exe /C powershell.exe -executionpolicy bypass -file example.ps1 >> c:\ps.log ?

the ps.log should give you an error if its even running.

Thanks willougd for your help. Tried this one also. Action has been completed successfully with exit code 0 but that script did not run. No clue what is the issue is. :cry:

Assuming you’ve ran the code manually as the system user on the target machine and the code is sound?

It’s difficult to guess without some idea of what the Power she’ll is trying to do.

Consider the normal limitations of the BigFix client environment -it runs as LocalSystem and in 32-bit mode by default.

Include action uses wow64 redirection false to force 64-bit mode.
If the Powershell script is trying to connect to a network UNC share, that won’t work as LocalSystem.

@SubhrajitPyne

@jgstew suggested testing this Fixlet, which demonstrates firing a .ps using a BigFix action.
https://bigfix.me/fixlet/details/3860

When you test this Fixlet downloaded from bigfix.me, not using your own .ps, but using the .ps that comes with the demo, do you end up with the “config_powershell.log” output file in your “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData__Global\Logs” folder?

I am asking you test this to help isolate if the issue is with your .ps or with the BigFix agent you are running the action on.

I just tried it and the demo worked great.

At 11:17:45 -0500 - actionsite (http://BrollyTest:52311/cgi-bin/bfgather.exe/actionsite)
   Relevant - Run: PowerShell Script - Windows - TEMPLATE (fixlet:228)
At 11:17:45 -0500 - 
   ActionLogMessage: (action:228) Action signature verified for Execution
   ActionLogMessage: (action:228) starting action
At 11:17:45 -0500 - actionsite (http://BrollyTest:52311/cgi-bin/bfgather.exe/actionsite)
   Wow64 redirection disabled. action uses wow64 redirection {not x64 of operating system} (action:228)
   Command succeeded delete No 'C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\actionsite\__createfile' exists to delete, no failure reported (action:228)
   Command succeeded createfile until  (action:228)
   Command succeeded delete No 'C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\actionsite\powershell.ps1' exists to delete, no failure reported (action:228)
   Command succeeded move __createfile powershell.ps1 (action:228)
   Command started - waithidden C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File powershell.ps1 (action:228)
At 11:17:45 -0500 - 
   Encryption: optional encryption with no certificate; reports in cleartext
At 11:17:53 -0500 - 
   Report posted successfully
At 11:17:53 -0500 - actionsite (http://BrollyTest:52311/cgi-bin/bfgather.exe/actionsite)
   Command succeeded (Exit Code=0) waithidden C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File powershell.ps1 (action:228)
At 11:17:53 -0500 - 
   ActionLogMessage: (action:228) ending action
At 11:17:53 -0500 - actionsite (http://BrollyTest:52311/cgi-bin/bfgather.exe/actionsite)
   Not Relevant - Run: PowerShell Script - Windows - TEMPLATE (fixlet:228)

image

Yes I didi that. Manually, that code is running fine, even in fixlet debugger it is running fine.

1 Like

Thanks brolly33 for your help. I tried this one also. Problem is, the code contains 150 lines, and sometimes i need to bypass the { by {{ when function comes. So i am trying to execute the .ps1 file from the location itself by calling powershell.exe.

If it runs fine manually and in filet debugger, it might mean your ps1 file needs to run on user account rather than system account as BigFix agent.

Perhaps you can use psexec (https://docs.microsoft.com/en-us/sysinternals/downloads/psexec) to see whether you ps1 file works with system account. And if your ps1 file needs to run on user account, override (https://developer.bigfix.com/action-script/reference/execution/override.html) may help.

2 Likes

@SubhrajitPyne Thanks for giving us the results from that test. So you can run a simple .ps script, but your specific script is not executing well. You might need to share the contents of the .ps with us in order to try to figure out what in your script is causing either “Failure to Launch” or “Failure to Complete”.

Thank you so much brolly33. The issue was in my script. It calls namap which causes a dos window open. So, the script terminates there and it never goes further…

1 Like