根据有关PowerShell类型加速器的这一技术文章,有几十种称为类型加速器的类型别名。确实,以下命令
[psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::get
在我的系统上返回80个加速器。
但是, [accelerators]::get
的速记似乎失败了:
无法找到类型的加速器。确保集会包含此类型已加载。在线: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
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