PowerShell Type Accelerators – shortcuts to .NET classes

Type Accelerators are a great PowerShell feature that allows shortcuts to .NET classes. When writing .NET code, once a namespace is imported with the ‘using’ directive, types in that namespace can be used without referencing the namespace itself:

[csharp]using System.Collections.Generic;
List l = new List();
// Instead of:
System.Collections.Generic.List l = new System.Collections.Generic.List();[/csharp]

However, it’s not possible to do that in PowerShell, which can make code somewhat lengthy. At RAVN, we use a number of library objects that have long namespace paths such as ‘Ravn.AutonomyTools.Idol.Query’. Scripts using these libraries can often become very verbose. Enter PowerShell Type Accelerators. You’ve probably been using them in your scripts without realising, here are some more common ones:

[powershell][hashtable] # System.Collections.Hashtable
[wmi] # System.Management.ManagementObject
[psobject] # System.Management.Automation.PSObject
[regex] # System.Text.RegularExpressions.Regex[/powershell]

So how do we find more accelerators available in PowerShell? A dictionary of the available accelerators can be obtained by using the static ‘Get’ method of the ‘System.Management.Automation.TypeAccelerators’ class:

[powershell]$accelerators = [System.Management.Automation.PSObject].Assembly.GetType(

The TypeAccelerators class is private, thus the workaround through PsObject. As the ‘Get’ property returns a dictionary, it’s possible to return details of a particular accelerator, or to search by namespace:



[powershell]$Namespace = ‘System.Collections’
$accelerators::Get.GetEnumerator() | ? { $_.Value.FullName -match "^$Namespace" }[/powershell]

So how can Type Accelerators be used to make code less verbose? It’s possible to add and remove custom type accelerators for any .NET class. System.Collections.List appears often in my scripts, and I’ve created the ‘strlist’ accelerator for it:

[powershell]$Name = ‘strlist’
$Type = ‘System.Collections.Generic.List[string]’
$accelerators::Add($Name, $Type)[/powershell]

It’s now possible to reference a string list using ‘strlist’:

[powershell][strlist]$l = @()
$l -join ‘,'[/powershell]

And what about removing accelerators that are no longer required? Just as simple as adding them:


For our professional services library, I’ve added three functions: Add-TypeAccelerator, Get-TypeAccelerator, Remove-TypeAccelerator, as wrappers to the functionality detailed above. Now, on module import, custom accelerators are loaded, including ones like ‘autnquery’ to simplify the use of ‘Ravn.AutonomyTools.Idol.Query’.