Revision #2

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