forked from PaulGrevink/PowerShell-Snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleparams.ps1
More file actions
39 lines (33 loc) · 754 Bytes
/
Exampleparams.ps1
File metadata and controls
39 lines (33 loc) · 754 Bytes
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
36
37
38
39
# Exampleparams.ps1
Param (
# Switch
[Switch]$Myswitch,
# Input validation
[Parameter(mandatory=$true)]
[ValidateSet("ABC","XYZ")]
[String]$Environment
)
function main()
{
if($Myswitch)
{
Write-Host "Switch myswitch is set."
}
if ($Environment -eq "ABC")
{
Write-Host "Parameter Environment is now ABC"
}
if ($Environment -eq "XYZ")
{
Write-Host "Parameter Environment is now XYZ"
}
}
main
# To see switch in action run
# PS> Exampleparams -Myswitch
#
# parameter $Environment is mandatory, the value is validated
# PS> Exampleparams -Environment XYZ
#
# Swiches en parameters can be combined
# PS> Exampleparams -Myswitch -Environment XYZ