-
Book Overview & Buying
-
Table Of Contents
Mastering PowerShell Scripting - Fourth Edition
By :
Type operators are designed to work with and test .NET types. The following operators are available:
-as-is-isnotThese operators may be used to convert an object of one type into another, or to test whether or not an object is of a given type.
The -as operator is used to attempt to convert a value into an object of a specified type. The operator returns null (without throwing an error) if the conversion cannot be completed.
For example, the operator may be used to perform the following conversions:
"1" -as [Int32]
'String' -as [Type]
If the attempt to convert the value fails, nothing is returned and no error is raised:
$true -as [DateTime]
The -as operator can be useful for testing whether a value can be cast to a specific type, or whether a specific type exists.
For example, the System.Windows.Forms assembly is not imported by default and the System.Windows...