Sign in
Home
Library
Wiki
Learn
Gallery
Downloads
Support
Forums
Blogs
Resources For IT Professionals
United States (English)
Россия (Pусский)
中国(简体中文)
Brasil (Português)
Skip to locale bar
Page Details
First published by
Chen V
(MVP, Microsoft Community Contributor)
When:
1 Apr 2014 6:40 AM
Last revision by
Peter Geelen
(MVP, Microsoft Community Contributor)
When:
18 Jul 2019 7:04 PM
Revisions:
7
Comments:
5
Options
Revision #2
Wiki
>
TechNet Articles
>
PowerShell: How to use Switch Parameter?
>
Revision #2
PowerShell: How to use Switch Parameter?
You are currently reviewing an older revision of this page.
Go to current version
What is Switch Parameter?
001
Help
about_Functions_Advanced_Parameters
How to Use Switch Parameter?
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
Param
(
[
Parameter
(
Mandatory
=
$false
)
]
[Switch]
$ColorText
)
How
to
consume
switch
parameter?
Demo
function
if
switch
-colortext
is
included
you
get
color
text
output
if
not
plain
text
with
default
host
color
Function
Demo
{
Param
(
[
Parameter
(
Mandatory
=
$false
)
]
[Switch]
$ColorText
)
if
(
$ColorText
-eq
$false
)
{
Write-Host
"Plain Text"
}
elseif
(
$ColorText
-eq
$true
)
{
Write-Host
"Color Text"
-ForegroundColor
Green
}
}
Demo