ProcessToRunonBan - Pass arguments when null #285
Replies: 5 comments 4 replies
-
Can powershell be set to allow optional parameters? |
Beta Was this translation helpful? Give feedback.
-
It can. The parameters themselves are optional, but if the parameter name is included then it requires some value. I'm probably going to workaround this with the 'big old monster parameter' for now, but it may be something to consider for your next release :) I appreciate the work you do! |
Beta Was this translation helpful? Give feedback.
-
If the software passed "" around each parameter, would that be sufficient? |
Beta Was this translation helpful? Give feedback.
-
I just tested that and it appears that PowerShell will accept empty strings there. So that would resolve this for PowerShell at least! |
Beta Was this translation helpful? Give feedback.
-
Solution is to add single quotes around the IPBan variables, so that they always return as a string (even an empty string). Then PowerShell will always run. For example: <add key="ProcessToRunOnBan" value="C:\Program Files\PowerShell\7\pwsh.exe|-Command "& 'C:\Program Files\IPBan\Send-OpenSearch.ps1' -Banned 1 -IPAddress '###IPADDRESS###' -Username '###USERNAME###' -Count '###COUNT###' -Source '###SOURCE###' -Log '###LOG###'""/> |
Beta Was this translation helpful? Give feedback.
-
When utilizing
ProcessToRunOnBan
with a PowerShell script (and I assume other stuff), the script is unable to run if there is a missing variable. For example,Consider the config:
If a scenario in which ###USERNAME### is null, the script will not run spitting out 'Missing an argument for parameter' (though this is not logged by IPBan or anything else)
If the IPBan could instead spit out the string
null
or some other pre-defined string, that would let me write the PowerShell script to handle that scenario. Of course, that should probably be an additional config option as to not interfere with existing deployments.The only workaround I can think of without this option, would be using one massive parameter and adding some arbitrary delimiter. I'm open to suggestions if someone has a better way though.
Beta Was this translation helpful? Give feedback.
All reactions