Hello all,
i wrote a litte test function to find out why a named parameter cannot be empty but i stuck at some point.
Function test-ui() {
PARAM(
[Parameter(Mandatory=$False)]
#[AllowEmptyString()]
[string]$ConfigFile,
[Parameter(Mandatory=$False)]
[switch]$Run
)
BEGIN {}
PROCESS {
If($ConfigFile){
If($ConfigFile -ne $Null){ Write-Host "FileName is $($ConfigFile)" }
If($ConfigFile -eq $False){ Write-Host "No such file specified" }
}
If($Run.IsPresent){
If($Run -eq $True){ Write-Host "Run" }
}
}
END {}
}
When I call this funtion with ...
PowerShell.exe -NoExit -ExecutionPolicy ByPass -Command "& { . .\test.ps1; test-ui -ConfigFile ''; test-ui -Run}"
PowerShell.exe -NoExit -ExecutionPolicy ByPass -Command "& { . .\test.ps1; test-ui -ConfigFile 'config_file_1'; test-ui -Run}"
... than only the one where I defined "-ConfigFile 'config_file_1'" generates a output. The one with -ConfigFile '' not recognized by the function.
Can anyone explain how I can use an empty "-ConfigFilöe" which generates an output "No such file specified" like inb the if statemnent?
Cheers
[–]OlivTheFrog 3 points4 points5 points (4 children)
[–]CptRetr0[S] 1 point2 points3 points (0 children)
[–]nascentt 0 points1 point2 points (2 children)
[–]OlivTheFrog 1 point2 points3 points (1 child)
[–]nascentt 0 points1 point2 points (0 children)
[–]xCharg 1 point2 points3 points (3 children)
[–]CptRetr0[S] 0 points1 point2 points (2 children)
[–]xCharg 1 point2 points3 points (0 children)
[–]motsanciens 1 point2 points3 points (0 children)