Datasheet
UNDERSTAND VARIABLES AND TYPES 27
Getting Started with
Windows PowerShell
Basics
PART 1
WriteContentTo Method System.Void...
WriteTo Method System.Void...
Item ParameterizedProperty System.Xml....
AdminContentDB Property System.Stri...
CentralAdmin Property System.Xml....
ConfigDB Property System.Stri...
DatabaseServer Property System.Stri...
FarmAccount Property System.Stri...
Passphrase Property System.Stri...
Notice how the attributes that are de ned within the
Farm
XML element show as
properties of the object and that the
TypeName
property is
System.Xml
.XmlElement
. Do you notice anything missing? How about the
OuterXml
prop-
erty or the
Name
or
OwnerDocument
properties, all of which are public members of
the
System.Xml.XmlElement
class?
is is due to the dynamically created
PSObject
object that wraps the
System
.Xml.XmlElement
object and adds all of the child attributes and elements of the
XML document as properties, hiding the built-in properties. To be clear, the built-in
properties are still there; they’re just not showing up when you query for them using
the default options of the
Get-Member
cmdlet. To see all of the available properties
and methods, use the
-View
parameter when calling the
Get-Member
cmdlet and
specify
All
:
$config.Farm | gm -View All
.
ere will be times when there is a con ict between the adapted properties and the
built-in properties. Consider if the
Farm
element had an attribute named
Name
. If
you typed
$config.Farm.Name
, would you get the XML attribute or the built-in
property corresponding to the element name? In this scenario, you’d get the XML
attribute value, but what if you wanted the built-in value? To get to the built-in
value, you would access it via a special property named PSBase:
$config.Farm
.PSBase.Name
.
Windows PowerShell also has what are known as type extensions. Type extensions
are modi cations to a type that expose some additional functionality and thus
make the type work in a more convenient way. Take a look at the members of the
Get-SPProcessAccount
cmdlet to see this in action:
PS C:\> Get-SPProcessAccount | gm
TypeName: Microsoft.SharePoint.Administration.i
SPProcessAccount
c01.indd 27c01.indd 27 5/16/2011 11:12:33 AM5/16/2011 11:12:33 AM