Online Training On SharePoint
                      

Sunday 5 October 2008

Getting All the Web Objects URL in a SharePoint farm using PowerShell Scripting

I tried to access the Web Objects URL in SharePoint Farm with the Power Shell. It was really easy to get them. Following are the steps to do so:

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=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c“)

We can also use the static method LoadWithPartialName on the Assembly class SharePoint. The syntax would be:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
(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)

function AcessFarm
{
return [Microsoft.SharePoint.Administration.SPFarm]::Local
}

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.

filter AcessWebServices
{
$webServices = new-object Microsoft.SharePoint.Administration.SPWebServiceCollection($_)

$webServices
}

filter AcessWebApplication
{
$_.WebApplications
}

filter AcessSiteCollection
{
$_.Sites
}

filter AcessWeb
{
$_.AllWebs
}

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


No comments:

Related Posts with Thumbnails