Powershell command not running thorugh BigFix

I need to run the below command through BigFix. can anyone help me on this?
Command -
& “C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1” -a fetch-config -m ec2 -s -c file:“C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json”

Also, I am trying to run through BigFix by using below command, but it got completed with exit code=1.
waithidden powershell.exe -ExecutionPolicy Bypass & “C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1” -a fetch-config -m ec2 -s -c file:“C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json”

I’m not sure what you’re trying to do with that ‘&’ symbol, but the way to run a PowerShell script is to use the -File parameter to powershell.exe.

I’m not completely confident in how PowerShell handles the quoted parameters, but you might try

waithidden powershell.exe -ExecutionPolicy Bypass -File "C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m ec2 -s -c file:"C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json"

@JasonWalker We should run with ‘&’ symbol. And I just want to say, I run this command manually it works and run without any error.

FYI, I have also used the mention command it got completed with exit code = -196608
waithidden powershell.exe -ExecutionPolicy Bypass -File “C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1” -a fetch-config -m ec2 -s -c file:“C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json”

If you’re using the & symbol the way I think you are, it’s being interpreted by the CMD.EXE shell to run one command and then run another, but I don’t see how that would actually pipe it to the spawned PowerShell command. In any case when you’re running it in the BESClient you don’t have a running shell to interpret the ‘&’ character.

Maybe you could approximate it with

waithidden cmd.exe -c "powershell.exe -ExecutionPolicy Bypass -File "C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m ec2 -s -c file:"C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json""

or possibly

`waithidden cmd.exe /c “powershell.exe -ExecutionPolicy Bypass & “C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1” -a fetch-config -m ec2 -s -c file:“C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json””’

We have used command in the past for Powershell but we have typically used waithidden cmd.exe /c powershell.exe -ExecutionPolicy Bypass -command “Enter Command to execute here” OR dos powershell.exe -ExecutionPolicy Bypass -command “Enter Command to execute here”
I think if you are going to do it like that you could also do something like this to have the & within the quotes for the command:
waithidden powershell -ExecutionPolicy bypass -Command “& ‘c:\temp\powershellscript.ps1’”

I think Jason is right in that the & isn’t being processed as part of the command but rather trying to be processed by waithidden as a parameter for powershell.exe.

But I don’t really prefer the dos option because it will proceed with other commands without waiting but it will interpret the same way as cmd.exe /c does.

1 Like