Switch parameters

Switch parameters are parameters without any need to assign any value to them. As the name suggests, they act as a switch. By default, their values are $false. Once these parameters are mentioned in the command line, their values become $true. We can use this switch parameter to perform our checks and run their respective script blocks. The following example is a function that connects to a vCenter server or vCloud Director server based on the input that we provide. As parameter values, we accept ServerName and UserName to connect to the server, Password for the connection, and another parameter that will act as a switch. If we mention –VCServer in the command line, then the Connect-VIServer cmdlets will be executed; if –VCDServer ...

Get Mastering PowerCLI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.