Posted On February 7, 2020

PowerShell: Special Parameter datatype [switch]

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Special Parameter datatype [switch]
# Demo of a simple function to turn lights on and off
function setLight{
param(
[switch]$on,
[switch]$off
)
if($on){write-host "Turn lights ON."}
if($off){write-host "Turn lights OFF."}
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Implementation of Anonymous Self Executing Function

JavaScript has this. It's a little known secret that PowerShell can do this as well.…

PowerShell: WinHTTP Proxy

The most direct method to set WinHTTP proxy settings on a Windows machine is to…

Basic CSS: Change the Color of Text

<h2>CatPhotoApp</h2><main> <p>Click here to view more <a href="#">cat photos</a>.</p> <a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange…