Finding Type Accelerators

by Sep 11, 2013

PowerShell maintains a list of shortcuts for .NET types to make coding more convenient for you. For example, to convert a string to a DateTime type, you can write:

[DateTime] '2013-07-02'

Behind the scenes, this is just a shortcut for the real type name "System.DateTime". You can always find out the real type by using the FullName property:

[DateTime].FullName

To get a list of all supported "type accelerators" (shortcuts), you can use the following piece of code. It returns all type accelerators implemented in PowerShell. This is extremely useful because it points you to all the internal .NET types the PowerShell developers thought were important:

[PSObject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::Get |
  Sort-Object -Property Value 

When you pipe the result to a grid view window, you can easily search for type accelerators. Simply enter part of the type name into the text box on top of the grid view window:

[PSObject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::Get |
  Sort-Object -Property Value |
  Out-GridView

Twitter This Tip! ReTweet this Tip!