Adding New Type Accelerators

by Feb 12, 2013

To access popular .NET types faster, PowerShell maintains a list of shortcuts called "type accelerators". That's why you can use the term "XML" for XML data instead of having to always write "System.Xml.XmlDocument":

PS> [xml].FullName

The list of type accelerators can be extended, so if you have additional .NET types that you use often, you can add them to that list.

This line adds a new type accelerator called "Path" that refers to the type "System.IO.Path":


You can now access all the highly useful static methods in that type very easily:

PS> [Path]::GetFileNameWithoutExtension('test.txt')

Note that type accelerators are just for your convenience. You can always use the full type name instead, too:

PS> [System.IO.Path]::GetFileNameWithoutExtension('test.txt')

Twitter This Tip! ReTweet this Tip!