Problem
You want to reduce the amount of redundant information in your script when you interact with classes that have long type names.
Solution
To reduce typing for static methods, store the type name in a variable:
$math = [System.Math] $math::Min(1,10) $math::Max(1,10)
To reduce typing for multiple objects in a namespace, use the f (format) operator:
$namespace = "System.Collections.{0}" $arrayList = NewObject ($namespace f "ArrayList") $queue = NewObject ($namespace f "Queue")
To reduce typing for static methods of multiple types in a namespace, use the f (format) operator along with a cast:
$namespace = "System.Diagnostics.{0}" ([Type] ($namespace f "EventLog"))::GetEventLogs() ([Type] ($namespace f "Process"))::GetCurrentProcess()
Discussion
One thing you will notice when working with some .NET classes (or classes from a thirdparty SDK), is that it quickly becomes tiresome to specify their fully qualified type names. For example, many useful collection classes in the .NET Framework all start with "System.Collections". This is called the namespace of that class. Most programming languages solve this problem with a using directive that lets you to specify a list of namespaces for that language to search when you type a plain class name such as "ArrayList". PowerShell lacks a using directive, but there are several options to get the benefits of one.
If you are repeatedly working with static methods on a specific type, you can store that type in a variable to reduce typing as shown in the solution:
$math = [System.Math] $math::Min(1,10) $math::Max(1,10)
If you are creating instances of different classes from a namespace, you can store the namespace in a variable and then use the PowerShell f (format) operator to specify the unique class name:
$namespace = "System.Collections.{0}" $arrayList = NewObject ($namespace f "ArrayList") $queue = NewObject ($namespace f "Queue")
If you are working with static methods from several types in a namespace, you can store the namespace in a variable, use the f (format) operator to specify the unique class name, and then finally cast that into a type:
$namespace = "System.Diagnostics.{0}" ([Type] ($namespace f "EventLog"))::GetEventLogs() ([Type] ($namespace f "Process"))::GetCurrentProcess()