Passing Switch parameters to packaged executable
Posted: Thu Feb 06, 2020 9:15 pm
I was looking for a way to pass switch parameters to a packaged exe and came across the following article.
https://www.sapien.com/blog/2015/11/30/ ... able-file/
While this is a clean workaround for not being able to handle [switch]'s, it still requires a value to be presented..
as such, in my code i have been using the following.
which resolves the issue altogether in that if the -SwitchValue is present on the command line, the switch becomes $True.
however....
If I use the Parameter editor it removes the empty value from the ValidateSet.
It would be really nice, if it could be modified to leave the empty value "" in as it is a valid value.
Packaged.exe -SwitchValue
https://www.sapien.com/blog/2015/11/30/ ... able-file/
While this is a clean workaround for not being able to handle [switch]'s, it still requires a value to be presented..
as such, in my code i have been using the following.
Code: Select all
param
(
[ValidateSet('True', 'False',"", IgnoreCase = $true)]
[string]$SwitchValue = "False"
)
if ($SwitchValue -ne "false") { [switch]$SwitchValue= $true }
else { [switch]$SwitchValue= $false }
however....
If I use the Parameter editor it removes the empty value from the ValidateSet.
Code: Select all
param
(
[ValidateSet('True', 'False', IgnoreCase = $true)]
[string]$SwitchValue = "False"
)
if ($SwitchValue -ne "false") { [switch]$SwitchValue= $true }
else { [switch]$SwitchValue= $false }
Packaged.exe -SwitchValue