【问题标题】:How can I get the PowerShell type accelerator list in an accelerated way?如何以加速方式获取 PowerShell 类型加速器列表?
【发布时间】:2018-02-09 10:04:11
【问题描述】:

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

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

在我的系统上返回 80 个加速器。

但是,它的简写 [accelerators]::get 似乎失败了:

找不到类型加速器。确保装配 包含此类型已加载。在 line:1 char:1

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

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

$PSVersionTable 返回以下数据:

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

操作系统是 Windows 7 x64。

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

【问题讨论】:

    标签: powershell powershell-4.0 type-accelerators


    【解决方案1】:

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

    您需要自己添加:

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

    【讨论】:

    • 哦,所以我必须添加加速器。谢谢。
    • 除非您使用的是 3.0 版(Windows 8 / Server 2012),否则是的 :-)
    • 似乎是为 PS 5 / Win 7 添加的。
    猜你喜欢
    • 2016-06-23
    • 2010-11-11
    • 1970-01-01
    • 1970-01-01
    • 2015-06-21
    • 2012-05-28
    • 2011-02-09
    • 2018-09-02
    • 1970-01-01
    相关资源
    最近更新 更多