Specifying parameter attributes
In this section, we will discuss the parameter
attributes and how to set them. The attributes falling under this category define the different attributes of the parameter itself. Let's take a closer look at the most useful and common options available to define parameter attributes and their uses:
Mandatory
argument: This argument indicates that this particular parameter is compulsory, otherwise it is optional. For example, if I am writing a function to connect to a vCenter server and doing some work and I want the vCenter name to be provided at runtime, then the following code makes sure that the cmdlet call will fail without the$VCName
parameter:Param ( [parameter(Mandatory=$true)] [String]$VCName )
Position
argument: We define the positional argument to specify which value will be assigned to which parameter by the position of the values at runtime, without the need to specify the parameter name. PowerShell will understand which parameter the value...