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: Execute as System Elevated Session with a Domain Administrator account

Part 1: Relaunch script in the context of Elevated System privileges: ############# Ensure that Program…

PowerShell: Audit Failed Logins of A User

$username='rambo' function auditLockouts($userName,$domainController,$refreshMinutes=1){ function getLockouts($domainControler){ # Requirement: # Domain Controllers Audit Group Policy has been…

PowerShell: Replicate All Domain Controllers Immediately

<#Author: KimConnect.comVersion: 0.1Purpose:- After a change has been issued against a "logon server", that domain…