Datasheet

24 CHAPTER 1
WINDOWS POWERSHELL 101
Windows PowerShell was able to convert the comma-separated list of items to an
array dynamically.  is is part of Windows PowerShells adaptive type system that
facilitates the automatic conversion of one type to another.
The Adaptive Type System
To examine how the adaptive type system works, we start by looking at an earlier
example:
PS C:\> $farm = Get-SPFarm
PS C:\> $farm.GetType().FullName
Microsoft.SharePoint.Administration.SPFarm
In this example, the
Get-SPFarm
cmdlet is returning back an
SPFarm
object, but
we didnt have to declare the variable type explicitly as is necessary with most pro-
gramming languages, such as C#. Windows PowerShell was able to set the variable
dynamically to the correct type. We could have explicitly set the type by using what
is known as a type literal. Type literals are just the type name surrounded by square
brackets:
[Microsoft.SharePoint.Administration.SPFarm]
.  e following
sets the variable again, but this time, it explicitly sets the variable type. If the
Get-
SPFarm
cmdlet should return a di erent type, then an exception would be thrown:
PS C:\> [Microsoft.SharePoint.Administration.i
SPFarm]$farm = Get-SPFarm
e interesting thing about the adaptive type system is that, as its name suggests, it
is able to adapt a value by converting it from one type to another dynamically:
PS C:\> [xml]$config = @”
>> <Farm FarmAccount=”sharepoint\spfarm”
>> ConfigDB=”SharePoint_ConfigDB”
>> AdminContentDB=”SharePoint_Content_Admin”
>> DatabaseServer=”spsql1”
>> Passphrase=”Pa`$`$w0rd”>
>> <CentralAdmin Port=”1234” AuthProvider=”NTLM”>
>> <Servers>
>> <Server Name=”spsvr1” />
>> </Servers>
c01.indd 24c01.indd 24 5/16/2011 11:12:33 AM5/16/2011 11:12:33 AM