-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06 ValidateCount.ps1
More file actions
35 lines (29 loc) · 1.12 KB
/
Copy path06 ValidateCount.ps1
File metadata and controls
35 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<#
.SYNOPSIS
Shows arguments with count validation attribute
.DESCRIPTION
This script is using named arguments with ValidateCount attribute.
This validation assumes collection type and allows only specified number of elements.
.EXAMPLE
& './06 ValidateCount.ps1' -Value one,two,three
This example will work as there are enough values in collection.
.EXAMPLE
& './06 ValidateCount.ps1' -Value 1,2,3,4,5,6
This example will fail because there are too many values in collection.
.EXAMPLE
& './06 ValidateCount.ps1' -Value 10,20
This example will also fail because there are too few values in collection.
.EXAMPLE
& './06 ValidateCount.ps1' -Value (Get-ChildItem 06*)
This example will also fail because one element is not collection type.
.LINK
https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters
#>
param (
[ValidateCount(3,5)]
$Value
)
if ($Value) {
'The type of value: {0}' -f $Value.Gettype()
'Number of values: {0}' -f$Value.Count
}