How to use ValidateSet with Switch Statement

How to use ValidateSet with Switch StatementBy Michael J. Thomas

Use validateset with a switch statement to put together more complex tasks. In the example below I use voicemail messages received from parents in which you can gather the information and then send out notifications to the teachers of the student status by copying the information to the clipboard and being able to paste it in the desired method of communication. 

I did not include other code to show how to email this information or send it in another manner. I wanted to keep this simple to understand how to use a validateset with a switch statement in order to take advantage of implementing complex tasks with your functions. You can use this information and put together an on-boarding process for provisioning accounts and user roles.




function New-Voicemail {
param(
[string]$Name,
[ValidateSet(6,7,8)]$Grade,
[ValidateSet("Tarde","Early","Absence")]$Reason

)
$Info = "The Following Student Name: $Name Grade: $Grade Reason: $Reason Today"
Set-Clipboard $Info
Switch ($Reason){

"Tarde"{ Write-Host $Info -ForegroundColor Yellow }
"Early"{ Write-Host $Info -ForegroundColor Green }
"Absence"{ Write-Host $Info -ForegroundColor Red }
}
}

Comments

Popular posts from this blog

Add-RemoteDesktopUsers

Keep All Network Connections Private ( Set-PrivateNetwork )

Invoke-Reprofile