Powershell one-liner works at Admin CLI, but not via Task?

Anyone know why the following works fine at the cmd.exe prompt but completes with an empty file in a BigFix Task? Here’s the line from my client log file:

Command succeeded (Exit Code=0) waithidden powershell.exe -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "('C:') | % { gci -Path $_ -File -Recurse -Force -ErrorAction SilentlyContinue | where { $_.name -eq 'preoobe.cmd' -or $_.name -eq 'winrm.cmd' } | select name,length,lastwritetime,fullname | Export-CSV -NoTypeInformation -Append 'C:\BigFixAudits\audit-20190209-220725.txt'}" (action:117464240)

Copying everything between “waithidden” and “(action…” into an administrative cmd.exe session creates a file with 11 lines of data, but the Task-run command generates an empty file.

(FYI: The “where” filter is just to grab some sample data…I’m not actually looking for those files.)

Any ideas?

– John

1 Like

Weird additional datapoint: running the same command as a Scheduled Task run by SYSTEM only generates a single line of data, but it’s still not blank. Curious…

Hello John,

I wonder if your action doesn’t work as expected because of curly brackets, which are used in actions for relevance substitution.

See the following KB article for more details:
https://www-01.ibm.com/support/docview.wss?uid=swg21506259

Regards,
Vitaliy

1 Like

Hi, Vitaliy!

It’s not a bad suggestion, but the log entry is showing the actual command being run by the BigFix agent, not the action relevance script. I left that out since the command appeared to be making it through to the client just fine and since it’s a mess of escaped brackets, parameters, and calculated timestamps. I’ve included it here as “evidence”, but I’m confident in saying that it’s not a bracket problem.

parameter "AuditName" = "audit"
parameter "Query" = " $_.name -eq 'preoobe.cmd' -or $_.name -eq 'winrm.cmd' "
folder create "C:\BigFixAudits"
waithidden powershell.exe -NoProfile -ExecutionPolicy Bypass -NonInteractive -Command "({"'" & concatenation "','" of names of drives whose (type of it is "DRIVE_FIXED") & "'"}) | % {{ gci -Path $_ -File -Recurse -Force -ErrorAction SilentlyContinue | where {{ {parameter "Query"} } | select name,length,lastwritetime,fullname | Export-CSV -NoTypeInformation -Append 'C:\BigFixAudits\{parameter "AuditName"}{("-" & (year of it as string & month of it as two digits & day_of_month of it as two digits) of date (local time zone) of it & "-" & (two digit hour of it as string & two digit minute of it as string & two digit second of it as string) of time (local time zone) of it) of now}.txt'}"
1 Like

You mentioned using an admin session for running the command.
Since the Client runs as the SYSTEM account, have you tried to use RunAs?

See more details here:
https://developer.bigfix.com/action-script/reference/execution/override.html

Regards,
Vitaliy

I don’t have an account that I could use across our install base other than SYSTEM. And, honestly, it should work a SYSTEM, so the default agent run state should be fine. :frowning:

The Administrator and SYSTEM accounts do work differently. You can use psexec to create a cmd window with the SYSTEM account and see if it works there?

1 Like

Do you have any reasons to run such big and complex command “directly” by waithidden ?
from my experience the less errors when it is done through “appendfile\createfile” and after running this created run.bat with redirecting output and error streams to files.

Trying to avoid actually writing anything to the drive. The command will actually be no less complex in a .ps1 file…just on multiple lines instead of one.

BigFix writes all time something to the drive.
several bytes more or less… I don’t think that it could be a problem :slight_smile:

1 Like

But one-liners are just so elegant! :wink:

Putting this into a script-created ps1 file will also allow me to add some troubleshooting steps much more easily… we’ll see.

1 Like