Useful PowerShell tips
The tips included below are not specific to a PowerShell module, however, some of the tips might only be appicable to cmdlets in a certain module.
Cmdlet Input
For cmdlets have input parameters with nested arrays or IDictionary containing array values, array of objects should be used, instead of array of a specific type (e.g., array of strings). For cmdlets use integer value of number of seconds as input, New-TimeSpan cmdlet can be used to convert minutes, hours or days to seconds, e.g., (New-TimeSpan -Days 7).TotalSeconds.
Cmdlet Output
Some resource instance returned from a cmdlet will only have resource ID for referenced object, e.g., Pool property of a LUN (in Unity) To get details of the referenced object, use corresponding Get cmdlet for the resource type with the ID, e.g., using Get-Pool to get details of the pool.Instances in output can be filtered based on their property values by using Where-Object command, for example, Get-Host $unity -Identify | Where-Object Name -eq “HOST1”, will display hosts with name HOST1. To learn more about the Where-Object command, please use “help Where-Object”.
Get Cmdlet
Get cmdlet with Name parameters will return a single instance that matches with a given name (case sensitive). For resource types where non unique name is allowed (e.g., Host), exception will be thrown in case of multiple instances with the same name. To get IDs with the name, use Identify parameter and filter output accordingly. Name parameter will not be supported for resource types that do not have a Name property. Identify parameter will not be supported either (unless other property could be used instead of Name).
Force Parameter
For all cmdlets where the Force parameter is supported, the parameter is used to skip confirmation before performing the operation. It is not related to the “force” parameter (if any) in Unisphere REST API.
Only for Unity : If Unisphere REST API has a parameter with name “force”, it will be “Force
Switch and Boolean Parameter in New and Set Cmdlets
For same parameter, switch parameter type will be used in New cmdlet, and boolean parameter type will be used in Set cmdlet. If default value of a parameter is True, the parameter type will be boolean instead of switch in the New cmdlet.