PowerShell Variables in ExternalParameters don't work?

Started by Staj, December 16, 2020, 09:46:55 AM

Previous topic - Next topic

Staj

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

Filipp Sudanov

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



Staj

I thought the same thing but the nxagentd.conf on disk and the Agent Configuration that matches for the node in NetXMS are all identical, as written. I couldn't work it out either.

Filipp Sudanov

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).