Datasheet
14 CHAPTER 1
•
WINDOWS POWERSHELL 101
In Windows PowerShell, an object’s type is represented by wrapping the object in
brackets (for example,
[type name]
). is is most commonly seen when accessing a
static method or property of a type, such as the
LoadWithPartialName
method or
the
Local
property. However, rather than using a period to access the object member,
you use a double colon (
::
). Types are explained in more detail later in this chapter.
To instantiate new objects, you use the New-Object cmdlet, as shown in the following
example that demonstrates creating a new quota template:
$webService = [Microsoft.SharePoint.Administration.i
SPWebService]::ContentService
$quota = New-Object Microsoft.SharePoint.Administration.i
SPQuotaTemplate
$quota.Name = “Team Site”
$quota.StorageMaximumLevel = 2GB
$quota.StorageWarningLevel = 1.5GB
$webService.QuotaTemplates.Add($quota)
is example loads an
SPWebService
object via the static
SPWebService.
ContentService
property, which is used to save the quota template that is instan-
tiated on the next line via the
New-Object
cmdlet. If you type
Get-Help New-
Object
in your Windows PowerShell console, you’ll be presented with a detailed
explanation of how the cmdlet works, including how to pass arguments into the
object’s constructor.
NOTE
Notice in the example that the property values are set using the standard
GB
units (could also have been
MB
). Windows PowerShell recognizes these as standard types
and automatically converts them to the number of bytes specifi ed. Try it for yourself.
Simply enter
1GB
in your Windows PowerShell console window. You should see an output
of
1073741824
.
e trick to being successful with Windows PowerShell is to learn the object model
of the application you want to manipulate as well as any available out-of-the-box
cmdlets; the rest is just syntax. e problem you’ll nd with SharePoint is that the
object model is huge and the number of available cmdlets can be staggering, so
don’t get frustrated as you begin your journey.
Discover Cmdlets and Objects
When you rst start working with SharePoint, one of the rst challenges that you
will face is nding the cmdlets that are needed to accomplish a particular task. is
c01.indd 14c01.indd 14 5/16/2011 11:12:31 AM5/16/2011 11:12:31 AM