Datasheet
UNDERSTAND VARIABLES AND TYPES 23
Getting Started with
Windows PowerShell
Basics
PART 1
In this example, we call the
GetType()
method of the string value
“Tessa”
. From
this, you can see that
“Tessa”
is a fully quali ed
System.String
object.
ESCAPE CHARACTER
Strings can be defi ned using either double quotes or single quotes. This is a conve-
nience feature that makes it easier to embed double or single quotes in a string without
having to escape the quote using the escape character (
`
):
PS C:\> “Tessa says: ‘Learn PowerShell!’”
Tessa says: ‘Learn PowerShell!’
PS C:\> ‘Tessa says: “Learn PowerShell!”’
Tessa says: “Learn PowerShell!”
PS C:\> “Tessa says: `”Learn PowerShell!`””
Tessa says: “Learn PowerShell!”
The escape character can also be used to break a command across multiple lines by
escaping the newline character:
PS C:\> $site = Get-SPSite `
>> “http://portal”
>>
PS C:\>
Here are a few more examples demonstrating some common built-in types:
PS C:\> $true.GetType().FullName
System.Boolean
PS C:\> (23).GetType().FullName
System.Int32
PS C:\> (23.0).GetType().FullName
System.Double
PS C:\> (2,3).GetType().FullName
System.Object[]
In the rst example, you can see that, to use a Boolean value of True, you use the
built-in variable called
$true
(for False, use
$false
). e second and third exam-
ples demonstrate how to check the type of an integer or double value by wrapping
the value in parentheses. Parentheses are used a lot in PowerShell to control the
execution order.
e last example is perhaps the most interesting. It creates an object array, which
is explained in more detail in the next section, but the interesting part is that
c01.indd 23c01.indd 23 5/16/2011 11:12:33 AM5/16/2011 11:12:33 AM