Type Shortcuts

Type Shortcuts

  • Comments 9

PSMDTAG:FAQ: What is a TYPE SHORTCUT?
PSMDTAG:FAQ: What are the TYPE SHORTCUTS?

 

Type shortcuts are a Windows PowerShell feature that allows you to reduce the amount of typing you have to do when specifying a type. 

 

For example, the following 2 statements produce the same result:

[System.Text.RegularExpressions.Regex]"^c.*"

[Regex]"^c.*"

 

Jim Truher produced the following list of type shortcuts available in V1.0 (NOTE: The WMI ones will be available in RC2 as noted in: http://blogs.msdn.com/powershell/archive/2006/06/26/647038.aspx )

 

 

[int]         typeof(int)
[int[]]       typeof(int[])
[long]        typeof(long)
[long[]]      typeof(long[])
[string]      typeof(string)
[string[]]    typeof(string[])
[char]        typeof(char)
[char[]]      typeof(char[])
[bool]        typeof(bool)
[bool[]]      typeof(bool[])
[byte]        typeof(byte)
[double]      typeof(double)
[decimal]     typeof(decimal)
[float]       typeof(float)
[single]      typeof(float)
[regex]       typeof(System.Text.RegularExpressions.Regex)
[array]       typeof(System.Array)
[xml]         typeof(System.Xml.XmlDocument)
[scriptblock] typeof(System.Management.Automation.ScriptBlock)
[switch]      typeof(System.Management.Automation.SwitchParameter)
[hashtable]   typeof(System.Collections.Hashtable)
[type]        typeof(System.Type)
[ref]         typeof(System.Management.Automation.PSReference)
[psobject]    typeof(System.Management.Automation.PSObject)
[wmi]         typeof(System.Management.ManagementObject)
[wmisearcher] typeof(System.Management.ManagementObjectSearcher)
[wmiclass]    typeof(System.Management.ManagementClass)

 

Jeffrey Snover [MSFT]
Windows PowerShell/Aspen Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

 

PSMTAG:DOTNET: Language shortcuts for type specifications

PSMTAG:LANGUAGE: Language shortcuts for type specifications

Leave a Comment
  • Please add 2 and 2 and type the answer here:
  • Post
  • Can we make our own type shortcuts?
  • Sure thing:

    [C:\temp]
    PS:8 > $Process = [System.Diagnostics.Process]

    [C:\temp]
    PS:9 > $Process::GetProcessById(1234)

    Lee
  • Ah; very handy.
  • Jim overlooked some of the type accelerators in that list, probably since it was getting so repetitious. It looks like the following also all work:
    [byte[]]
    [double[]]
    [single[]]
    [type[]]
    [array[]]
    [decimal[]]
    Obviously, all of the "fundamental" important types can be arrayed with an accelerator, including both [type] and [array] itself.
    One is missing, possibly via oversight: [float[]] fails. Since [float] is actually System.Single and since [single[]] works, this is not a major impairment.
  • [void] also seems to exists as of RC2 or so.

  • Anyone know of a way to discover these programatically? Or is it embedded too deep?

  • This script might do it (Gets type accelerators in CTP3): http://powershell.com/cs/media/p/691.aspx

  • How can I delete this. I do not need it!

Page 1 of 1 (9 items)