The <typename>
/ <typename[]>
notation is used solely in PowerShell's syntax diagrams, to denote the data type (.NET type) of a given parameter.
Whether typename
represents the simple name of a .NET type without also including its namespace component (e.g. <string>
) or the full type name (e.g. <System.String>
) varies situationally:
Full (namespace-qualified) type names are only shown if you use -?
or Get-Help
and the target command's help information happens to be provided via separate, MAML-based help files.
- Additionally,
System.Enum
-derived parameters are shown by their values rather than their type name.
Otherwise - which notably includes written-in-PowerShell functions and scripts using comment-based help - you get the simple names only.
Similarly, you only get the simple type names if you use Get-Command
-Syntax
- irrespective of how the target command's help is implemented.
A typename
followed by []
indicates that a given parameter accepts an array of instances of the given type - e.g. <string[]>
.
Note:
Technically, if only a simple type name is displayed, the display is ambiguous, as types of a given name may exist in multiple namespaces. That said, in the typical case it'll be clear what types are being referred to, notably with .NET primitive types such as string
, int
, ...
When in doubt, use reflection to determine the full type name; e.g., to determine the full .NET type name of the New-Object
cmdlet's -Property
parameter:
(Get-Command New-Object).Parameters['Property'].ParameterType.FullName
Given PowerShell's flexible automatic type conversions, a given argument needn't be of the exact type declared by the target parameter; it can be any type that PowerShell can convert to the target type. This is generally helpful, but can sometimes lead to surprising behavior. Notably, a <string>
parameter accepts argument of (almost) any type, given that any object can be converted to a string, though not always meaningfully - see this answer for more information.
For additional information on how to read syntax diagrams, namely with respect to which parameters are positional and which ones are optional, see this answer.
Notably, the <typename>
syntax-diagram notation differs from how types are represented in actual PowerShell code, where a type name must be enclosed in [...]
to form a so-called type literal (e.g. [string]
).
Additionally, namespace qualification of typename
is required, except if a given type is located directly in the System.
namespace (e.g. [datetime]
for System.DateTime
) or if a type accelerator is used (e.g. [regex]
); if a namespace component must be specified, the System.
component may be omitted.
See this answer for more information about type literals.