Adding New Type Accelerators

Share |

Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus

13 Free SQL Tools from Idera

Free Ebook: Mastering Powershell

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!

Posted Feb 12 2013, 06:00 AM by ps1
Copyright 2012 All rights reserved.