Datasheet

WORK WITH OUTPUT 35
Getting Started with
Windows PowerShell
Basics
PART 1
e following example demonstrates how to use the
SPSitePipeBind
object with
the
Get-SPWeb
cmdlet to return all the
SPWeb
objects within the speci ed site
collection:
$site = Get-SPSite http://portal
$webs = $site | Get-SPWeb
$webs = $site.ID | Get-SPWeb
$webs = “http://portal” | Get-SPWeb
As you can see, you  rst get an
SPSite
object and then use that object to pipe into
the
Get-SPWeb
cmdlet using the three possible representations. Each approach
returns the same information.  is technique allows the cmdlets to remain rela-
tively simple and avoid having to provide di erent parameter sets for each possible
combination, while at the same time, it allows the user to use the information avail-
able without having to transform it to something else.
Format Your Results
To display the contents of a variable to the console, enter the variable alone on a
single line and the data will be written to the console using a default view. You can
also use the
Write-Output
cmdlet to achieve the same thing:
PS C:\> Write-Output $farm
Name Status
---- ------
SharePoint_ConfigDB Online
To format the results in a di erent way, Windows PowerShell provides four cmdlets
that can take an object or collection of objects as input and format them in a par-
ticular way:
PS C:\> Get-Command -verb format
CommandType Name Definition
----------- ---- ----------
Cmdlet Format-Custom Format-Custom [[-...
Cmdlet Format-List Format-List [[-Pr...
Cmdlet Format-Table Format-Table [[-P...
Cmdlet Format-Wide Format-Wide [[-Pr...
c01.indd 35c01.indd 35 5/16/2011 11:12:35 AM5/16/2011 11:12:35 AM