Welcome to MSDN Blogs Sign in | Join | Help

Type Shortcuts

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

Published Wednesday, July 12, 2006 5:12 PM by PowerShellTeam

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Interesting Finds: July 12, 2006

Wednesday, July 12, 2006 11:12 PM by Jason Haley

# re: Type Shortcuts

Can we make our own type shortcuts?
Thursday, July 13, 2006 1:13 PM by nlhowell

# re: Type Shortcuts

Sure thing:

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

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

Lee
Thursday, July 13, 2006 1:35 PM by PowerShellTeam

# re: Type Shortcuts

Ah; very handy.
Friday, July 14, 2006 2:53 PM by nlhowell

# re: Type Shortcuts

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.
Monday, July 31, 2006 4:59 PM by Alex K. Angelopoulos

# re: Type Shortcuts

[void] also seems to exists as of RC2 or so.

Tuesday, January 29, 2008 10:22 AM by marco.shaw

# re: Type Shortcuts

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

Thursday, November 20, 2008 6:41 PM by EBGreen

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker