Datasheet
UNDERSTAND VARIABLES AND TYPES 25
Getting Started with
Windows PowerShell
Basics
PART 1
>> </CentralAdmin>
>> </Farm>
>> “@
>> $config.GetType().FullName
>>
System.Xml.XmlDocument
PS C:\>
is interesting example demonstrates two concepts. e rst is what is known as
a here string. Here strings are special markers that indicate that everything between
them is a complete string (the opening marker,
@”
, and the closing marker,
“@
, must
appear on their own lines as shown in the example). is is very handy when trying
to construct variables with complex string representations.
e second is that Windows PowerShell was able to convert this string to a
System.Xml.XmlDocument
object automatically by simply prefacing the vari-
able name with the type alias
[xml]
. But the power doesn’t end there. Windows
PowerShell includes the concept of object adapters that essentially take certain
“foreign” objects and wrap them in a special .NET type known as the PSObject. e
PSObject
then exposes custom methods and properties that make working with
the object more user-friendly and “object oriented.” ere are several object adapt-
ers that come with Windows PowerShell and provide speci c implementations of
the
PSObject
.
To put this in context, Windows PowerShell provides an object adapter for working
with
System.Xml.XmlDocument
objects, which means that you can access the
Farm
node of the XML (the root element) by simply accessing the nodes as though
they were properties, as shown here:
PS C:\> $config.Farm
FarmAccount : sharepoint\spfarm
ConfigDB : SharePoint_ConfigDB
AdminContentDB : SharePoint_Content_Admin
DatabaseServer : spsql1
Passphrase : Pa$$w0rd
CentralAdmin : CentralAdmin
c01.indd 25c01.indd 25 5/16/2011 11:12:33 AM5/16/2011 11:12:33 AM