Datasheet

36 CHAPTER 1
WINDOWS POWERSHELL 101
ese cmdlets o er a variety of techniques for outputting data, including the ability
to specify which properties of the object you’d like to have displayed and the use of
wildcards, regular expressions, and script blocks:
PS C:\> $site = Get-SPSite http://portal
PS C:\> $site | Format-List Url, Host*, i
{[int]($_.Usage.Storage/1MB)}
Url : http://portal
HostHeaderIsSiteName : False
HostName : portal
[int]($_.Usage.Storage/1MB) : 5
is example gets an
SPSite
object and uses the
Format-List
cmdlet (which can
also be abbreviated using the
fl
alias) to return back the
Url
property using the
exact name of the property, all the properties that start with
Host
using the wild-
card character
*
, and  nally, a script block to return the amount of space consumed
by the site collection in megabytes.
Script blocks provide a convenient mechanism to add simple or complex logic to the
output mechanism. Any amount of code can be included in the script block, which
will be executed for each item passed into the cmdlet. You can add a label to the
script block column by changing the script block to the following:
@{Expression={[int]($_.Usage.Storage/1MB)}; Label=”Size”}
If you want to see all the properties, pipe the object to the desired formatter without
specifying any properties (with the exception of
Format-Wide
, which is meant to
show a single property). Now run the same command, but use the
Format-Table
cmdlet (the default view for most object types) and then the
Format-Custom
cmdlet:
PS C:\> $site | Format-Table Url, Host*, {[int]($_.Usage.S
torage/1MB)}
Url HostHeaderIsSi HostName [int]($_.Usage
teName .Storage/1MB)
--- -------------- -------- -------------
http://portal False portal 5
PS C:\> $site | Format-Custom Url, Host*, {[int]($_.Usage.
Storage/1MB)}
c01.indd 36c01.indd 36 5/16/2011 11:12:35 AM5/16/2011 11:12:35 AM