在PowerShell中,您可以使用[xml]来表示[System.Xml.XmlDocument]。你知道我在哪里可以找到这些类型加速器的列表吗?
这些加速器是特定于PowerShell还是.NET?
这些加速器是特定于PowerShell还是.NET?
自从四年前提出并回答这个问题以来,PowerShell 已经继续发展。@KeithHill 简明扼要的答案不幸地已经不再适用。我稍微挖掘了一下,发现必要的类只是有点 less exposed。好消息是,现在可以使用这一行代码显示类型加速器列表...
[psobject].assembly.gettype("System.Management.Automation.TypeAccelerators")::Get
在Connect post中归功于Jaykul。
以下是部分输出:
Key Value --- ----- Alias System.Management.Automation.AliasAttribute AllowEmptyCollection System.Management.Automation.AllowEmptyCollectionAttribute AllowEmptyString System.Management.Automation.AllowEmptyStringAttribute AllowNull System.Management.Automation.AllowNullAttribute array System.Array bool System.Boolean byte System.Byte char System.Char CmdletBinding System.Management.Automation.CmdletBindingAttribute datetime System.DateTime decimal System.Decimal adsi System.DirectoryServices.DirectoryEntry adsisearcher System.DirectoryServices.DirectorySearcher double System.Double float System.Single single System.Single guid System.Guid hashtable System.Collections.Hashtable int System.Int32 . . .
2014.03.15 更新
截至PowerShell Community Extensions (PSCX) 版本3.1.0,您现在可以使用类型加速器来列出所有类型加速器并只需调用此命令:
[accelerators]::get
最可靠的方法是按照Oisin在这篇优秀博客文章中所演示的方式进行操作:
PS> $acceleratorsType = [type]::gettype("System.Management.Automation.TypeAccelerators")
PS> $acceleratorsType
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
False False TypeAccelerators System.Object
PS> $acceleratorsType::Add("accelerators", $acceleratorsType)
PS> [accelerators]::Get
Key Value
--- -----
int System.Int32
...
PowerShell 类型别名 对应的 .NET 类型 [int] System.Int32 [int[]] System.Int32[] [long] System.Int64 [long[]] System.Int64[] [string] System.String [string[]] System.String[] [char] System.Char [char[]] System.Char[] [bool] System.Boolean [bool[]] System.Boolean[] [byte] System.Byte [byte[]] System.Byte[] [double] System.Double [double[]] System.Double[] [decimal] System.Decimal [decimal[]] System.Decimal[] [float] System.Single [single] System.Single [regex] System.Text.RegularExpression.Regex [array] System.Array [xml] System.Xml.XmlDocument [scriptblock] System.Management.Automation.ScriptBlock [switch] System.Management.Automation.SwitchParameter [hashtable] System.Collections.Hashtable [psobject] System.Management.Automation.PSObject [type] System.Type [type[]] System.Type[]
[System.Net.NetworkInformation.IPStatus]
PowerShell在尝试解析名称时也会提供一个前导"System.",因此如果您正在使用System*命名空间中的内容,则不需要显式使用。
[Net.NetworkInformation.IPStatus]
这里是更完整的列表:
Key Value
--- -----
adsi System.DirectoryServices.DirectoryEntry
adsisearcher System.DirectoryServices.DirectorySearcher
array System.Array
bigint System.Numerics.BigInteger
bool System.Boolean
byte System.Byte
char System.Char
cimclass Microsoft.Management.Infrastructure.CimClass
cimconverter Microsoft.Management.Infrastructure.CimConverter
ciminstance Microsoft.Management.Infrastructure.CimInstance
cimtype Microsoft.Management.Infrastructure.CimType
cultureinfo System.Globalization.CultureInfo
datetime System.DateTime
decimal System.Decimal
double System.Double
float System.Single
guid System.Guid
hashtable System.Collections.Hashtable
initialsessionstate System.Management.Automation.Runspaces.InitialSessionState
int System.Int32
int16 System.Int16
int32 System.Int32
int64 System.Int64
ipaddress System.Net.IPAddress
long System.Int64
mailaddress System.Net.Mail.MailAddress
powershell System.Management.Automation.PowerShell
psaliasproperty System.Management.Automation.PSAliasProperty
pscredential System.Management.Automation.PSCredential
pscustomobject System.Management.Automation.PSObject
pslistmodifier System.Management.Automation.PSListModifier
psmoduleinfo System.Management.Automation.PSModuleInfo
psnoteproperty System.Management.Automation.PSNoteProperty
psobject System.Management.Automation.PSObject
psprimitivedictionary System.Management.Automation.PSPrimitiveDictionary
psscriptmethod System.Management.Automation.PSScriptMethod
psscriptproperty System.Management.Automation.PSScriptProperty
psvariable System.Management.Automation.PSVariable
psvariableproperty System.Management.Automation.PSVariableProperty
ref System.Management.Automation.PSReference
regex System.Text.RegularExpressions.Regex
runspace System.Management.Automation.Runspaces.Runspace
runspacefactory System.Management.Automation.Runspaces.RunspaceFactory
sbyte System.SByte
scriptblock System.Management.Automation.ScriptBlock
securestring System.Security.SecureString
single System.Single
string System.String
switch System.Management.Automation.SwitchParameter
timespan System.TimeSpan
type System.Type
uint16 System.UInt16
uint32 System.UInt32
uint64 System.UInt64
uri System.Uri
version System.Version
void System.Void
wmi System.Management.ManagementObject
wmiclass System.Management.ManagementClass
wmisearcher System.Management.ManagementObjectSearcher
xml System.Xml.XmlDocument