What is OutputType?
If you’ve seen the OutputType attribute when writing a cmdlet or advanced function, you might wonder what we use it for.
The goal of the OutputType attribute is to provide a mechanism for tools to know what your cmdlets may output without running them. If they know that without running it, they can provide useful services – such as tab completion, data flow analysis, etc.
For example:
Get-Process | Where-Object { $_.
When you push TAB, we can look at the pipeline that you’ve just typed, do static analysis of the cmdlet that Where-Object is filtering, and then only display properties from the OutputType (if that cmdlets specifies one).
When writing a cmdlet or advanced funciton, you can type whatever you want as the output type, but you’ll mislead tools if it doesn’t represent a real type that can be reasoned against. The reason that we support the string syntax (in addition to the regular type syntax) is so that the type doesn’t need to be loaded in order for the script to run.