Exchange 2010 : Getting Familiar with PowerShell Parameters

In this article we will be getting familiar with Exchange cmdlet parameters types.

Parameters are elements that provide information to the cmdlet, either identifying an object and its attributes to act upon, or controlling how the cmdlet performs its task. The name of the parameter is preceded by a hyphen (-) and followed by the value of the parameter. The hyphen in front of the parameter name tells the Exchange Management Shell that the word that immediately follows the hyphen is a parameter that is passed to the cmdlet and that the next separate word after the parameter is the value of the parameter.

Parameter input is either optional or required depending upon the cmdlet you are running.

Identity Parameters :
The -Identity parameter allows you to specify the object you want to take an action on. The –Identity parameter can accept different value types like alias, GUID, ADObjectID, DistinguisedName, SMTPAddress, UPN etc. When you run "Get" command, you are not required to run the "-Identity" parameter with the few cmdlets like get-mailbox. The –Identity parameter is required when you modify object using "Set" cmdlets. This is because the cmdlet needs to know exactly which object it should modify when the cmdlet is run.

Example: If you run get-mailbox cmdlet without using the –Identity parameter, it will show the first 1000 mailboxes, as the default SizeLimit is 1000. If you wish to see information about a particular mailbox, let’s say user MikeRay’s mailbox then you will have to use -identity parameter to let the get-mailbox cmdlet know that you wish to see only MikeRay’s mailbox info.


**

Boolean Parameters:**

Boolean parameters are used when you need to set a parameter value for a cmdlet to either true(enable) or false (disable). The value that you assign to a Boolean parameter is stored in the configuration of the object that you're modifying. When you supply a value to a Boolean parameter, you must use the values $True or 1, or $False or 0. The dollar sign ($) must be included with $True and $False.

Example : 
**

Switch Parameters :
**Switch parameters are commonly used to indicate whether the current command should proceed with additional prompting or to enable an alternate option for the command being run. This state isn't saved between commands. On some cmdlets, the cmdlet may run as though the switch parameter was included on the command line, even if you didn't include it yourself. This behavior commonly occurs with the Confirm switch parameter on cmdlets that can cause data loss if they're inadvertently run. In the case of the Confirm switch parameter on such a cmdlet, the cmdlet will always prompt for confirmation before running unless you explicitly tell the cmdlet not to by overriding the switch parameter. You can override the switch parameter by including the Confirm switch parameter on the command line with a value of :$False. Unlike any other parameters, the colon character (:) is required between switch parameters and the value $False.

Example : Below example instructs the Remove-ReceiveConnector cmdlet to display a confirmation prompt before deleting the Receive connector "client Ex01"

.

Common Parameters:
Common parameters are parameters that are automatically added to all commands by the Shell. These parameters perform functions that can be used with, or used by, the commands that they're run against. Below are the list of optional common parameters.

Debug : The Debug parameter instructs the command to provide programmer-level detail about the operation.

ErrorAction : The ErrorAction parameter controls the behavior of the command when an error occurs. Values are as follows. Default value of this parameter is Continue, other values are stop, SilentContinue, Inquire which prompts for user action.

ErrorVariable : The ErrorVariable parameter specifies the name of the variable that the command uses to store errors that are encountered during processing. This variable is populated in addition to $ERROR.

OutVariable : The OutVariable parameter specifies the name of the variable that the command uses for objects that are output from this command. This is equivalent to piping the command to Set-Variable <name> -Passthru:$true

The OutVariable parameter specifies the name of the variable that the command uses for objects that are output from this command. This is equivalent to piping the command to Set-Variable <name> -Passthru:$true

Verbose : provides detaild informationabout the operation run by the cmdlet.

Whatif Switch :
The WhatIf switch instructs the command to which it is applied to run but only to display the objects that would be affected by running the command and what changes would be made to those objects. The switch does not actually change any of those objects. When you use the WhatIf switch, you can see whether the changes that would be made to those objects match your expectations, without the worry of modifying those objects.
The switch instructs the command to which it is applied to run but only to display the objects that would be affected by running the command and what changes would be made to those objects. The switch does not actually change any of those objects. When you use the switch, you can see whether the changes that would be made to those objects match your expectations, without the worry of modifying those objects.

Example :

ValidateOnly Switch :
The ValidateOnly switch instructs the command to which it is applied to evaluate all the conditions and requirements that are needed to perform the operation before you apply any changes. The ValidateOnly switch is available on cmdlets that may take a long time to run, have several dependencies on multiple systems, or affect critical data, such as mailboxes.

The switch instructs the command to which it is applied to evaluate all the conditions and requirements that are needed to perform the operation before you apply any changes. The switch is available on cmdlets that may take a long time to run, have several dependencies on multiple systems, or affect critical data, such as mailboxes.

When you apply the ValidateOnly switch to a command, the command runs through the whole process. The command performs each action as it would without the ValidateOnly switch. But the command doesn't change any objects. When the command completes its process, it displays a summary with the results of the validation. If the validation indicates that the command was successful, you can run the command again without the ValidateOnly switch.

Example : Get-Mailbox "Kim Akers" | Move-Mailbox -TargetDatabase "Executive Database" -ValidateOnly

Tip:
Using Wild Card 
To list all the Mailboxes starts with K
Get-Mailbox K*

Note : Parameter values containg a space need to be enclosed in double quotation marks.
Example : Get-Mailbox -OrganizationalUnit "contoso.com/Sales Users/Phoenix"