Command Help

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Optional Items

Brackets ([]) surround optional items. For example, in the New-Alias


cmdlet syntax description, the Scope parameter is optional. This is
indicated in the syntax by the brackets around the parameter name
and type:
[-Scope <string>]

Both the following examples are correct uses of the New-Alias cmdlet:
New-Alias -Name utd -Value Update-TypeData
New-Alias -Name utd -Value Update-TypeData -Scope global

A parameter name can be optional even if the value for that parameter is
required. This is indicated in the syntax by the brackets around the
parameter name but not the parameter type, as in this example from the
New-Alias cmdlet:
[-Name] <string> [-Value] <string>

The following commands correctly use the New-Alias cmdlet. The commands
produce the same result:
New-Alias -Name utd -Value Update-TypeData
New-Alias -Name utd Update-TypeData
New-Alias utd -Value Update-TypeData
New-Alias utd Update-TypeData

If the parameter name is not included in the statement as typed, Windows


PowerShell tries to use the position of the arguments to assign the
values to parameters.

The following example is not complete:


New-Alias utd

This cmdlet requires values for both the Name and Value parameters.

In syntax examples, brackets are also used in naming and casting to


.NET Framework types. In this context, brackets do not indicate an
element is optional.

Array Arguments
Brackets are also used in syntax descriptions to represent an array.
The following example shows the syntax for the Restart-Service cmdlet:
Restart-Service [-Name] <string[]> [-Include <string[]>]
[-Exclude <string[]>] [-Force] [-PassThru] [-Confirm] [-WhatIf]
[<CommonParameters>]

The Name parameter requires an argument. Specifically, it requires the


name of the service to be restarted. It can take a comma-separated list
of services, as in the following example:
Restart-Service RasAuto, RasMan, RemoteAccess

SEE ALSO
Get-Help

You might also like