PowerShell Variables in ExternalParameters don't work?
-
Making literal $ doesn't work for ExternalParameters in 3.6-300 it seems as per this other thread?
Unless there is some other way to run PowerShell commands?
nxagentd.conf portion:
ExternalParameter=Get-ScheduledTask(*):powershell.exe -NoProfile -Command "$$Parameter = \"$2\"; Write-Host (Get-ScheduledTask -TaskName \"$1\").$$Parameter"nxagentd.log portion:
2020.12.16 18:38:36.287 *D* [comm.cs.5 ] Received message CMD_GET_PARAMETER (699) 2020.12.16 18:38:36.287 *D* [comm.cs.5 ] Requesting parameter "Get-ScheduledTask("Test Task", "State")" 2020.12.16 18:38:36.287 *D* [comm.cs.5 ] H_ExternalParameter called for "Get-ScheduledTask("Test Task", "State")" "Spowershell -NoProfile -Command "$Parameter = \"$2\"; Write-Host (Get-ScheduledTask -TaskName \"$1\").$Parameter"" 2020.12.16 18:38:36.287 *D* [exec ] RunExternal called for "Get-ScheduledTask("Test Task", "State")" "Spowershell -NoProfile -Command "$Parameter = \"$2\"; Write-Host (Get-ScheduledTask -TaskName \"$1\").$Parameter"" 2020.12.16 18:38:36.287 *D* [exec ] RunExternal: command line is "powershell -NoProfile -Command "Parameter = \"State\"; Write-Host (Get-ScheduledTask -TaskName \"Test Task\").Parameter"" 2020.12.16 18:38:36.287 *D* [exec ] RunExternal (shell exec): worker thread created -
Are you sure that nxagentd.conf portion is exactly the same that the agent is running with? Was agent restarted to work with actual config?
For me "RunExternal (shell exec): worker thread created" only appears when ExternalParameterShellExec is used (by the way this soon gonna be reworked and all actions and external parameters will be lauched as ShellExec).I've tried with agent 3.6.300. Here's my config:
ExternalParameterShellExec=Get-ScheduledTask(*):powershell.exe -NoProfile -Command "$$Parameter = \"$2\"; Write-Host (Get-ScheduledTask -TaskName \"$1\").$$Parameter"And that's the log:
2020.12.16 03:41:40.720 *D* [comm.cs.50 ] Requesting parameter "Get-ScheduledTask("Test Task", "State")" 2020.12.16 03:41:40.720 *D* [comm.cs.50 ] H_ExternalParameter called for "Get-ScheduledTask("Test Task", "State")" "Spowershell.exe -NoProfile -Command "$$Parameter = \"$2\"; Write-Host (Get-ScheduledTask -TaskName \"$1\").$$Parameter"" 2020.12.16 03:41:40.720 *D* [exec ] RunExternal called for "Get-ScheduledTask("Test Task", "State")" "Spowershell.exe -NoProfile -Command "$$Parameter = \"$2\"; Write-Host (Get-ScheduledTask -TaskName \"$1\").$$Parameter"" 2020.12.16 03:41:40.720 *D* [exec ] RunExternal: command line is "powershell.exe -NoProfile -Command "$Parameter = \"State\"; Write-Host (Get-ScheduledTask -TaskName \"Test Task\").$Parameter"" 2020.12.16 03:41:40.720 *D* [exec ] RunExternal (shell exec): worker thread created -
-
I would restart the agent just to make sure, but you probably already did that.
There could be a few ways for the agent to read another config then the default one
- running it with -c <config_file_name>
- running it with -M <server_ip> - it would get config file from server
- configuration policies that add up to the config - they reside in system32/config/systemprofile/appdata/local/nxagentd/config_ap/ (or other user home folder, if agent is started under other user, not system one).
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login