As mentioned earlier, there
are more than 750 individual SharePoint 2013 commands. This section will get you started
working with some of the more common SharePoint commands for
PowerShell.
Working with the Farm
The highest-level SharePoint
administration object is the farm, which contains many key properties,
methods, and collections associated with the SharePoint farm. You can
access many of the farm’s properties using a specific SharePoint 2013
command.
For example, you can determine the farm’s status, display name, and version by using the Get-SPFarm command . The output of this command is nothing special. The default output for the SPFarm object is to display the Status and DisplayName. However, you learned earlier how to use Format-List to control formatting of the objects You can also pipe the output of Get-SPFarm through the Select-Object cmdlet to display specific properties so feel free to modify the output of the SPFarm object. To add the BuildVersion column to the output, use the following command:
Get-SPFarm | Select-Object DisplayName, Status, BuildVersion
To access an individual property on the SPFarm
object, use dot notation (.). You could also do this using a variable,
but that has its own complications. For example, to access the BuildVersion property of the SPFarm object, use the following command:
(Get-SPFarm).BuildVersion
The parentheses specify that you want the BuildVersion property of the result of the Get-SPFarm command. The result of the Get-SPFarm command is an SPFarm object. Without the parentheses, PowerShell would interpret your command as “get the BuildVersion property of the Get-SPFarm command,” which does not have a BuildVersion property. Figure 1 shows the result.
There are quite a few methods for the SPFarm object, such as backup and restore,
but we won’t cover any of these because SharePoint includes specific
cmdlets for many of these methods. There’s not much point spending time
learning how to work with the object model when you can simply run a
command that works more closely with the features you are trying to
leverage.
Working with the Farm Configuration
This section touches on two useful farm configuration commands. The Get-SPFarmConfig command returns farm-level configuration information for items that are not on the SPFarm object. Figure 2 displays example output of the Get-SPFarmConfig command.
You can use the corresponding Set-SPFarmConfig command to modify the values. It is a little bit more involved than a single command. You need to get the FarmConfig into a variable, change the value of the property, and then pipe the modified FarmConfig variable to the Set-SPFarmConfig command. Figure 3 shows example output.
The commands in Figure 3 modify the farm’s WorkFlowBatchSize
property, which determines how many workflows can be processed at one
time by the farm. The default value is 100. In this case, the setting
is changed to 105 and the value is written back to the farm.