如何以加速方式获取 PowerShell 类型加速器列表?

How can I get the PowerShell type accelerator list in an accelerated way?

根据this TechNet article关于PowerShell类型加速器的说法,有几十种类型别名称为类型加速器。的确,下面的命令

[psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::get

returns 我的系统上有 80 个加速器。

然而,它的 shorthand [accelerators]::get 似乎失败了:

Unable to find type accelerators. Make sure that the assembly that contains this type is loaded. At line:1 char:1

  •   + CategoryInfo          : InvalidOperation: (accelerators:TypeName) [], RuntimeException
      + FullyQualifiedErrorId : TypeNotFound
    

我也试过在发出命令之前用[System.Reflection.Assembly]::LoadWithPartialName("System.Management.Automation.TypeAccelerators")动态加载System.Management.Automation.TypeAccelerators程序集,但仍然失败。

$PSVersionTablereturns以下数据:

Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.42000
BuildVersion                   6.3.9600.18728
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2

OS 是 Windows 7 x64。

如何加速获取PowerShell类型加速器列表?

我知道这篇文章说它默认存在于 PowerShell 3.0 中,但我从未在任何其他开箱即用的版本中看到它,很可能在 4.0 版本中再次被删除。

您需要自己添加:

$TAType = [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")
$TAType::Add('accelerators',$TAType)

# this now works
[accelerators]::Get