I am having trouble passing parameters using a custom powershell plugin from a Windows machine running the NCPA 3.0.0.client.
To help with testing, I wrote the following PS script:
param (
[string]$F='John',
[string]$L='Doe',
[string]$M='E'
)
write-host "Success! $($F) $($M) modified $($L)."
Exit 0
Then, I try passing parameters, initially with Powershell named parameters like -F Joe -L Donuts, but that didn't work at all. Eventually I settled on using positional parameters, but have had issues getting that to work as well.
To test, I am modifying the nrdp.cfg on the Windows machine, restarting the service and then going to http://localhost:5693/gui/checks.
I have tried lots of combinations with varying results. For example:
%HOSTNAME%|TestArgs = plugins/testargs.ps1 --args Joe Donuts S"
returns Joe E Doe
Here are some of my notes, sorry they are a little disorganized. Keep in mind F used to be First, M - Middle, L - Last
-a did not work
--args 'G K B' not working at all
--args 'G,K,B' treats as first argument only
--args '-First G' not working
--args '--First G' not working
--args "-First G" not working
--args "-First 'G'"
--args -First G - specify a system string
--args -First "G" - Same
--args -First 'G' - Same
--args 'G','k' recognized first two params, but included quotes
--args Gar,k combined into 1 parameter.
--args "Gar ak","k" not working at all - Same with single quotes - doesn't seem to like spaces.
Gar,F,Eild - combined
"Gar","F","Eild" - correclty set first to "Gar" but combimed "F","Eild" together for last
"Gar,F,Eild" - combined into first
NCPA Powershell Plugin trouble passing arguments
-
- Posts: 3
- Joined: Tue Aug 18, 2015 1:01 pm
Re: NCPA Powershell Plugin trouble passing arguments
Hello @rfaulkner99,
For your PowerShell script to process the arguments correctly, you want the CLI input to be To get this behavior as a passive check, you can use
You can more intuitively figure out how to properly configure your plugin inputs by first going through the NCPA UI at https://your_NCPA_ip_address:5693/gui/api/ and selecting plugins and pluginname.ps1 and then entering your arguments into the argument box and adding arguments as necessary until you get your desired result.
For your PowerShell script to process the arguments correctly, you want the CLI input to be
Code: Select all
plugins/plugin.ps1 "arg1" "arg2" "arg3"
Code: Select all
%HOSTNAME%|TEST = plugins/test.ps1 --args "arg1" --args "arg2" --args "arg3"
April: Actively advancing awesome answers with ardent alliteration, aptly addressing all ambiguities. Amplify your acumen and avail our amicable assistance. Eagerly awaiting your astute assessments of our advice.
-
- Posts: 3
- Joined: Tue Aug 18, 2015 1:01 pm
Re: NCPA Powershell Plugin trouble passing arguments
Thanks! That got me further, and the API tip makes testing much easier.
The only thing I am stuck on now is getting it to pass a path with a space. Powershell expects it to be wrapped in quotes, but I have tried double-quoting and using \ as an escape character and neither work.
The only thing I am stuck on now is getting it to pass a path with a space. Powershell expects it to be wrapped in quotes, but I have tried double-quoting and using \ as an escape character and neither work.
Re: NCPA Powershell Plugin trouble passing arguments
That is a bug that should be fixed in NCPA 3.1.0.
April: Actively advancing awesome answers with ardent alliteration, aptly addressing all ambiguities. Amplify your acumen and avail our amicable assistance. Eagerly awaiting your astute assessments of our advice.
-
- Posts: 3
- Joined: Tue Aug 18, 2015 1:01 pm
Re: NCPA Powershell Plugin trouble passing arguments
OK, thanks for the information. Also, passing multiple arguments in a passive check using:
did not work for me either. When I do that, it only passes the last argument (arg3).
Is that also a bug?
Code: Select all
%HOSTNAME%|TEST = plugins/test.ps1 --args "arg1" --args "arg2" --args "arg3"
Is that also a bug?
Re: NCPA Powershell Plugin trouble passing arguments
This will work correctly in NCPA 3.1.0, which is scheduled to release very soon.
April: Actively advancing awesome answers with ardent alliteration, aptly addressing all ambiguities. Amplify your acumen and avail our amicable assistance. Eagerly awaiting your astute assessments of our advice.