Run Powershell Command in Bigfix

Trying to get the following command to work in a Bigfix task but I am getting a Error code=1. Any ideas?

STATUS: Running action...
Command succeeded parameter "PowerShellexe" = "C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe"
Command started - waithidden "C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe" -command Sync-AppvPublishingServer -ServerID 1
Command succeeded (Exit Code=1) waithidden "C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe" -command Sync-AppvPublishingServer -ServerID 1

— Result —
Evaluation completed successfully!

regset "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell]" "ExecutionPolicy"="Unrestricted"

parameter "PowerShellexe" = "C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe"

waithidden "{parameter "PowerShellexe"}" -command Sync-AppvPublishingServer -ServerID 1

I wouldn’t recommend setting the execution policy like that, instead use the “ExecutionPolicy” command line parameter to have it run this time only, regardless of the current ExecutionPolicy setting.

powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File <script_name>

Exit code 1 seems to be an uncaught “throw”: http://blogs.msdn.com/b/powershell/archive/2006/10/14/windows-powershell-exit-codes.aspx

1 Like

Try this:

waithidden "{parameter "PowerShellexe"}" -ExecutionPolicy Bypass -command "Sync-AppvPublishingServer -ServerID 1"

Instead of this:

No go. I still get the error code 1. Could it be because it is running as system? When I run this command from cmd.exe, it works fine, but it doesn’t translate properly when I run it in Bigfix.

PowerShell.exe -command Sync-AppvPublishingServer -ServerID 1

I don’t really know what this is trying to do, so I don’t know if that is why it isn’t working.

Trying running the command using PSExec as the system account and see if it works there, which should be a much closer match to the way BigFix will run it through the client.

Do you know of a way to pause the execution of the window to see the error it is generating?

Try this:

psexec cmd /K <your_command>

Does this test command work?: (it works on my systems)

waithidden "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -command "get-help | out-file C:\windows\temp\test_powershell.txt"

I created a task to test powershell and report the powershell major version through the exit code: http://bigfix.me/fixlet/details/5019

Related:
Powershell Help

I was able to run this command successfully.

1 Like

If the test command or task works, then the issue is not with powershell, that part is working.

based upon my limited testing with powershell recently, I do think you need the quotes around the command, like this:

waithidden powershell -ExecutionPolicy Bypass -command "Sync-AppvPublishingServer -ServerID 1"

But also, I think you need to make sure this works correctly when running as the system account using PSExec. I think that might be part of the issue.

I would also try running a powershell command with the following preceding it in the actionscript:

action uses wow64 redirection {not x64 of operating system}

When running powershell through bigfix it will use 32bit powershell which can cause issues if the powershell must be run using 64bit powershell on a 64bit OS to succeed. Using this in the actionscript causes BigFix to invoke the 64bit powershell instead of the 32bit powershell.


Related: