Wednesday, December 2, 2009

Listing all PowerShell type accelerators

Type accelerators are shortcuts (similar to aliases) for .NET type names.

For example:

[int]3.0
and
[system.int32]3.0

Are equivalent because there is a type accelerator that maps int to System.Int32. They can be very useful when dealing with longer type names such as System.Text.RegularExpressions.Regex ([regex]).

The way to list all the currently defined type accelerators is:

([type]::gettype("System.Management.Automation.TypeAccelerators"))::get | sort key

TypeAccelerators also has an Add function that can be used to define new type accelerators.