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

Ale*_*xei 3 powershell powershell-4.0 type-accelerators

根据该Technet关于Powershell类型加速器的文章,有几十种类型别名称为类型加速器。确实,以下命令

[psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::get
Run Code Online (Sandbox Code Playgroud)

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

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

找不到类型[加速器]。确保包含此类型的程序集已加载。在第1行:char:1 + [accelerators] :: get + ~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(accelerators:TypeName)[],RuntimeException + FullyQualifiedErrorId :TypeNotFound

我还尝试在发出命令之前动态加载System.Management.Automation.TypeAccelerators程序集[System.Reflection.Assembly]::LoadWithPartialName("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            
Run Code Online (Sandbox Code Playgroud)

操作系统是Windows 7 x64。

问题:如何以加速方式获取Powershell类型的加速器列表?

Mat*_*sen 6

我知道这篇文章说它默认存在于PowerShell 3.0中,但是我从未见过任何其他版本可用,很可能会在4.0版本中再次删除。

您需要自己添加:

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

# this now works
[accelerators]::Get
Run Code Online (Sandbox Code Playgroud)