I can use Test-Path to check whether the file name entered exists, but I'd like to avoid producing a system error if the user hits RETURN and the input string is blank. I thought the -ErrorAction Common Parameter would do the trick, but this:
$configFile = Read-Host "Please specify a config. file: "
$checkfile = Test-Path $configFile -ErrorAction SilentlyContinue
still produces:
Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\Scripts\testparm2.ps1:19 char:31
+ $checkfile = Test-Path <<<< $configFile -ErrorAction SilentlyContinue
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.TestPathCommand
Do I have to check that the string isn't blank or NULL explicitly?
I'm using PowerShell v2.0