PowerShell - Shorten namespace names so it's easier to access types
Any methods accepting Enums will accept strings, but this is for Enums only and where there is no ambiguity (meaning there are no other overloads with a signature matching strings in this fashion.)
If you're on powershell v2.0, you can (ab)use Type Accelerators. I blogged about this before, and Joel Bennett wrapped up my technique in a handy script:
http://poshcode.org/1869
UPDATE (2020): this link is broken, but for current versions of powershell there is an easier way.
using namespace System.Collections.Generic;
$list = new-object List # also: $list = [list]::new()
-Oisin
Lengthy types can be assigned to variables and then used via those variables:
# enum values
$rvk = [Microsoft.Win32.RegistryValueKind]
$rvk::Binary
$rvk::DWord
# static members
$con = [System.Console]
$con::CursorLeft
$con::WriteLine('Hello there')
# just to be sure, look at types
.{
$rvk::Binary
$con::WriteLine
$con::CursorLeft
} |
% { $_.GetType() }