Reader small image

You're reading from  Mastering PowerCLI

Product typeBook
Published inOct 2015
Reading LevelIntermediate
PublisherPackt
ISBN-139781785286858
Edition1st Edition
Languages
Right arrow
Author (1)
Sajal Debnath
Sajal Debnath
author image
Sajal Debnath

Sajal Debnath is a highly certified Cloud computing technocrat with more than 12 years of experience in virtualized data center design, Cloud computing, and BC/DR solutions. He is an EMCISA, VCAP-DCD/DCA, VCAP-CID/CIA, RHCE 4/5/6, RHCVA, Openstack, and ITIL certified person. He is presently associated with VMware Software India Pvt. Ltd. as a senior system engineer. Previously, he worked with France Telecom, Hewlett Packard, and many more in multiple roles. He is involved in prestigious Indian government projects, such as National Cloud, Digital Locker, and so on.
Read more about Sajal Debnath

Right arrow

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 is mentioned, then the Connect-CIServer cmdlets will be executed. So, run the following code snippet:

Function Connect-Server{
[CmdletBinding()]
 Param(
    [Parameter(Mandatory=$true)]
            [string]$ServerName,
            [string]$UserName...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering PowerCLI
Published in: Oct 2015Publisher: PacktISBN-13: 9781785286858

Author (1)

author image
Sajal Debnath

Sajal Debnath is a highly certified Cloud computing technocrat with more than 12 years of experience in virtualized data center design, Cloud computing, and BC/DR solutions. He is an EMCISA, VCAP-DCD/DCA, VCAP-CID/CIA, RHCE 4/5/6, RHCVA, Openstack, and ITIL certified person. He is presently associated with VMware Software India Pvt. Ltd. as a senior system engineer. Previously, he worked with France Telecom, Hewlett Packard, and many more in multiple roles. He is involved in prestigious Indian government projects, such as National Cloud, Digital Locker, and so on.
Read more about Sajal Debnath