Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Correct usage of [Validatenotnullorempty]

$
0
0

Hi

I have this function that accepts a directory fullname as inpu and just returns that and i would like it to throw an exception if a null or empty value is passed or when no value is passed at all.

function test {
Param
(
[Alias('FullName')]
[parameter(Mandatory=$true,ValueFromPipeLine=$true,ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Path
)
$path
}

PS C:\> dir c:\ -Filter users | test
C:\Users

PS C:\> dir c:\ -Filter Idontexist| test

Expecting an error saying a null or empty value was passed but no errors?

Is this expected behavior. Could someone clarify?


Viewing all articles
Browse latest Browse all 13067

Latest Images

Trending Articles



Latest Images