Changes

Jump to: navigation, search

Basic Windows PowerShell 1.0 Types

2,847 bytes added, 20:30, 18 November 2008
PowerShell Numeric Types
</pre>
As illustrated in the above PowerShell console output, a variable assigned the value 10.432 is stored as type ''Double'' by Windows PowerShell.To obtain only the full .Net type name use ''gettype().fullname'' as follows: <pre>PS C:\Users\Administrator> $myval.gettype().fullnameSystem.Int32</pre> A type may be explicitly set by prefixing the value with either the full or short type name. For example: <pre>PS C:\Users\Administrator> [byte] $myval = 10PS C:\Users\Administrator> $myval.gettype() IsPublic IsSerial Name BaseType-------- -------- ---- --------True True Byte System.ValueType</pre> In the case of explicitly making a value ''Decimal'', the value may be followed by the ''d'' character: <pre>PS C:\Users\Administrator> $myvalue = 10dPS C:\Users\Administrator> $myvalue.gettype() IsPublic IsSerial Name BaseType-------- -------- ---- --------True True Decimal System.ValueType</pre> == Specifying Hexadecimal Numbers == Hexadecimal numbers are specified in PowerShell using the same approach used by most other programming languages such as C, C++, C# and Java. The technique involves prefixing the number with ''0x''. For example: <pre>PS C:\Users\Administrator> 0x1233fadf305396447</pre> == PowerShell Boolean Type == Boolean values (which can be either 1 or 0) are defined in PowerShell using the .Net ''System.Boolean'' type (the short from of which is [bool]. For example, the following command assigns ''true'' to a variable of boolean type: <pre>PS C:\Users\Administrator> [bool] $myval = 1PS C:\Users\Administrator> $myval.gettype().fullnameSystem.Boolean</pre> When working with boolean variables, the pre-defined ''$true'' and ''$false'' variables may also be used: <pre>PS C:\Users\Administrator> [bool] $myval = $falsePS C:\Users\Administrator> $myvalFalse</pre> == PowerShell String Type == Strings in PowerShell are represented using the .Net ''System.String'' type. Strings may be single quoted or double quoted (details of which are covered in detail in the chapter entitled [[Windows PowerShell 1.0 String Quoting and Escape Sequences]]). A ''here-doc'' or ''here-string'' (a string containing large amounts of text on multiple lines) can be created by encapsulating the string in ''@[Quote][newline]'' and ''"@[Quote][Newline]'' sequences, using either single or double quotes: <pre>PS C:\Users\Administrator> $mystring = @'>> This is a single>> quoted here-string>> in PowerShell>> '@>>PS C:\Users\Administrator> $mystringThis is a singlequoted here-stringin PowerShell PS C:\Users\Administrator> $mystring = @">> This is a double>> quoted here-string>> in PowerShell>> "@>>PS C:\Users\Administrator> $mystringThis is a doublequoted here-stringin PowerShell</pre>

Navigation menu