1. To use Power Shell for SharePoint we need to log in into the server as the SharePoint object Model does not allow to access remotely.
2. Now we need to add the Microsoft.SharePoint Assembly in the Power Shell environment. To add the Microsoft.SharePoint assembly to the PowerShell environment we need to run the following command in Power Shell:
[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=18.104.22.168, Culture=neutral, PublicKeyToken=71e9bce111e9429c“)
We can also use the static method LoadWithPartialName on the Assembly class SharePoint. The syntax would be:
(Although the LoadWithPartialName has been deprecated.)
3. Now created functions and filters. With these we will get different objects and pass them through the Hierarchy. (Check the SharePoint Hierarchy)
This function will return the SPFarm object. We will pipe this object with the next Filter. This will get all the web services on the SharePoint Farm.
$webServices = new-object Microsoft.SharePoint.Administration.SPWebServiceCollection($_)
Now we need to pipe these functions and filters to get a table of WebURL of the Web objects in the Farm. The command looks like:
AcessFarm AcessWebServices AcessWebApplication AcessSiteCollection AcessWeb format-table -property url
The last format-table will put the output in a table format and the URL property of Web Objects will display only the URL's of all the Web Objects.
PowerShell is very strong feature and SharePoint Admin can do the magic with this. With the above command we can now access all the properties and method of SPWeb Objects. We can do many further advanced tasks with these objects.
You may also find interesting to read:
Getting SharePoint Server Version with PowerShell and Deploying custom SharePoint site collection with the help of PowerShell in Windows Server 2008