PowerShell - Abbreviation of Names to Simplify Type Access

Is there a way to reduce PowerShell namespace references?

Input [RootNameSpace1.NameSpace2.Namepsace3+SomeEnum]::SomeValue is a taxation and not very good expansion of the user. I understand that you can reference System level objects without a namespace, so [Type]::GetType(... will work. Is there any manifest that I could create or a command that I could use to shorten long namespaces?

+6
namespaces powershell
source share
2 answers

Any methods that accept Enums will accept strings, but this is only for Enums and where there is no ambiguity (which means there are no other overloads with a substring corresponding to the strings in this way.)

If you are using powershell v2.0, you can (ab) use type accelerators. I reported this earlier, and Joel Bennett wrapped my technique in a convenient script:

http://poshcode.org/1869

-Oisin

+6
source share

Long types can be assigned to variables and then used through these 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() } 
+5
source share

All Articles