Changes

Jump to: navigation, search

Basic Windows PowerShell 1.0 Types

1,218 bytes added, 20:13, 26 November 2008
PowerShell String Type
quoted here-string
in PowerShell
</pre>
 
== Windows PowerShell Type Casting ==
 
Clearly, PowerShell will make a judgement as to a value's type. Most of the time this is fine, but occasionally it is necessary to specifically specify the type. This is achieved using ''type casting''. Type casting involves preceding the value or variable with the short or long variable name enclosed in square brackets. For example, to force variable $x to be double (as opposed to the default Int32):
 
<pre>
PS C:\Users\Administrator> [double] $x = 10
PS C:\Users\Administrator> $x.gettype()
 
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Double System.ValueType
</pre>
 
Casting can similarly be used to cast a variable that would clearly ordinarily be assumed by PowerShell to be an integer type as a string:
 
<pre>
PS C:\Users\Administrator> [string] $mystring = 10
PS C:\Users\Administrator> $mystring.gettype()
 
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
</pre>

Navigation menu