Datasheet

UNDERSTAND VARIABLES AND TYPES 29
Getting Started with
Windows PowerShell
Basics
PART 1
is collection can then be passed into most cmdlets, such as the
Get-SPSite
cmdlet:
PS C:\> $siteUrls | Get-SPSite
Url
---
http://portal
http://teams
PS C:\>
In this particular example, the Windows PowerShell runtime is looping through
each item in the array and calling the
Get-SPSite
cmdlet for each item.  e
objects written to the pipeline are then grouped together to form a new collection
(an array of type
object[]
) that can then be passed into other cmdlets.
Multiple arrays can easily be combined to form a new array:
PS C:\> $siteUrls1 = @(“http://portal”, “http://teams”)
PS C:\> $siteUrls2 = @(“http://mysites”, “http://projects”)
PS C:\> $siteUrls1 += $siteUrls2
PS C:\> $siteUrls1
http://portal
http://teams
http://mysites
http://projects
PS C:\>
DECLARING EMPTY ARRAYS
Sometimes, you’ll need to create an empty array to which you can dynamically add ele-
ments for later processing. To declare an empty array, omit the values within the paren-
theses. You can then add items using the
+
operator (or the shorthand
+=
operator):
PS C:\> $siteUrls = @()
PS C:\> $siteUrls = $siteUrls + “http://portal”
PS C:\> $siteUrls += “http://teams”
PS C:\> $siteUrls
http://portal
http://teams
PS C:\>
c01.indd 29c01.indd 29 5/16/2011 11:12:34 AM5/16/2011 11:12:34 AM