My Technet Gallery Scripts

It is not because I am not blogging that I am not busy :)

In the last months I have published several scripts to the Microsoft Technet gallery, that I want to summarize in this post:

1. Find Broken Inheritance in a SharePoint 2010 web application

This powershell script allows for enumeration through a SharePoint 2010 web application to identify all sites, document libraries, lists, folders and items for which the permission inheritance has been broken.

This script should be executed using a SharePoint 2010 Management Shell on one of the SharePoint servers in the farm with an account allowed to access all content.

2. Reset Broken inheritance in SharePoint 2010 site collection

this PowerShell script allows for resetting broken inheritance within a site collection. It will run through all subsites, lists, document libraries, folders and individual items, check if permission inheritance is broken and reset the inheritance.

3. Populate PictureUrl with values from CSV file

This PowerShell script allows you to populate the PictureUrl property of the User Profiles in SharePoint 2010 based on a provided CSV file, containing the username and the picture URL.

4. SharePoint document versions report

This script will generate a tab delimited text file with all the documents present is in the given web application in SharePoint 2010. It will list the documents, the size of the document, the number of versions, the sie of the versions and the total size. This report will enable you to identify large files throughout an entire web application and identify those files that have many versions and are basically eating up all your storage.

5. Find Connected Web Parts in Web application

This script locates all pages in an entire web application that uses connected web parts. the script runs through all the aspx pages in all document libraries of all sites in every site collection and checks if there are web part connections defined. If this is the case it will list the page and the provider and consumer web part title.

The script can easily be adapted to find specific web parts in an entire web application

6. Sync SharePoint 2010 User Profile PictureUrl attribute with AD attribute

This Powershell script allows you to synchronize an Active Directory custom attribute with the SharePoint 2010 user profile service application PictureUrl property. Usefull for companies that store picture url information in a custom attribute and want to replicate that information into SharePoint 2010. Normally this should be feasible by customizing the ForeFront Identity Manager used by the SharePoint 2010 User Profile Synchronization service, but this is not supported. The script can be easily customized to use a different extension attribute in Active Directory

Use this script in combination with a scheduled task on one of the SharePoint servers in the farm.

7. Find Web parts in SharePoint farm

he following powershell script will allow you to identify site collections where a given webpart is used. Very usefull during migrations when you have identified the web parts that cannot be upgraded and need to know where they are used. The script allows you to specify a scope of webapp or site collection to go through and look into the web part gallery to check if the web part is present.
Prerequisites for this script is having Powershell 2.0 deployed on the SharePoint 2007 server.
This post describes the implementation of rule based Active Directory groups (RBAG’s), maintained by a custom PowerShell script. The need for such rule based groups can vary. For example maintaining an Active Directory group that holds all members of a specific department can be challenging when no identity management system is available in the company. Hence the creation of this PowerShell script. The script allows for updating Active Directory groups based on a LDAP filter configured on specific Active Directory Groups.

Beware of /bin/ is SP2010 Url’s

Came across troubleshooting an issue with a site collection with the name bin. This site collection had a url like http://portal/sites/bin, making the default homepage http://portal/sites/bin/default.aspx. For some reason the site did not render and I got a HTTP 404 error. After analysis of the ULS logs not showing any trace of the request and the analysis of the IIS logs, I wnet looking for an answer on the interwebz. Stumbled upon the following article from Russ Michaels : http://www.michaels.me.uk/post.cfm/iis7-blocks-viewing-access-to-certain-folder-names

As it appears IIS 7 blocks access to urls where /bin/ is present in the Url.

The solution to this problem is to rename the site collection or remove the exception in the web.config of your web application as suggested by Russ.

I prefer the web.config approach on the web application level by adding the following section:

<?xml version="1.0"?>  
<configuration>  
 <system.webServer>  
   <security>  
    <requestFiltering> 
     <hiddenSegments>  
      <remove segment="bin" />  
     </hiddenSegments>  
    </requestFiltering>  
   </security>  
  </system.webServer> 
 </configuration>

How to change the language of a site in SP2010

Notice: the information in this post is not supported by Microsoft. The use of the method described below will revoke your support status for your environment. Use at your own risk

This question came up today and I remembered being able to change this for MOSS by changing the content database so I wondered if it would still work in SP2010.

Well, actually it does ….

The article I used as a source for MOSS can be found at http://sharepointlearn.blogspot.com/2008/12/changing-language-of-existing.html

the only change to the original article is that the Table name has changed in SP2010. Here is the updated information:

The language of the site is stored at SP Web level. It is stored in database in the AllWebs table. So you need to change the language in database whatever language you want. To change the language in database you need to fire following Query:

For changing the language of all sites in to ‘Dutch’ language:
UPDATE dbo.AllWebs SET Language = 1043

Changing the language of one site collection: (Dutch language)
UPDATE dbo.AllWebs SET Language = 1043 WHERE SiteId = [[SiteCollectionId]]

Changing the language of a single web or subsite: (Dutch language)
UPDATE dbo.AllWebs SET Language = 1043 WHERE Id = [[WebId]]

Note:
Before applying the new language, you need to verify that the language pack for the language that you want to apply is installed on your machine or not.

What Every SharePoint Admin Needs to Know About Host Named Site Collections by Kirk Evans

been a while, busy busy busy …. what else :)

just wanted to point out a very good article that sums up all you need to know about Host Named site collectiosn in SharePoint 2010.

Find the original article by Kirk Evans at

http://blogs.msdn.com/b/kaevans/archive/2012/03/27/what-every-sharepoint-admin-needs-to-know-about-host-named-site-collections.aspx

Cumulative updates packaging changed for SharePoint 2010

while browsing the updates page on Technet I found:

The packaging of cumulative updates changed as of August 31, 2011. The following packages are provided for cumulative updates:
• SharePoint Foundation 2010
• SharePoint Foundation 2010 + SharePoint Server 2010
• SharePoint Foundation 2010 + SharePoint Server 2010 + Project Server 2010
As a result of the new packaging, it is no longer necessary to install the SharePoint Foundation cumulative update and then install the SharePoint Server cumulative update.

Source: http://technet.microsoft.com/en-us/sharepoint/ff800847

Remove HTTP Response Headers for internet facing SharePoint sites

if you are serious about to publish an internet facing SharePoint site you have to consider security. One of the first things a possible hacker will inspect are the HTTP Response Headers. I usually use the Firefox Developper toolbar to check the HTTP Response Headers of my SharePoint sites. (Information Menu -> View Response Headers)

Without cleaning the reponse headers you will see something like:

Connection: Keep-Alive
Expires: Mon, 23 May 2011 13:56:12 GMT
Date: Tue, 07 Jun 2011 13:56:13 GMT
Content-Type: text/html; charset=utf-8
<strong>Server: Microsoft-IIS/7.5</strong>
Cache-Control: private, max-age=0
Last-Modified: Tue, 07 Jun 2011 13:56:12 GMT
<strong>SPRequestGuid: 2ba6c04a-f3ca-40be-a543-7fb2448bd92e
X-SharePointHealthScore: 0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 14.0.0.5130</strong>
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding

200 OK

Now, what I needed removing was all the SharePoint stuff, the ASP.NET stuff and the server information (marked in bold). Luckily I was not the first guy out there to do so and I used Stefan Goßner’s post (http://blogs.technet.com/b/stefan_gossner/archive/2008/03/12/iis-7-how-to-send-a-custom-server-http-header.aspx) as a lead to achieve what I wanted.

I ended up creating a custom HttpModule for removing the excess information in combination with adding a section to the web.config for the custom Headers added by SharePoint as they were not removed by the HttpModule after my initial testing.

Actions performed:
1. Create a folder named App_Code in the IIS folder of the SharePoint site where the headers need to be removed
2. Create a file with notepad named CustomHttpModule.cs
3. Edit with notepad:

using System;
using System.Text;
using System.Web; 

namespace Custom.ServerModules
{
  public class CustomHttpHeaderModule : IHttpModule
  {
    public void Init(HttpApplication context)
    {
      context.PreSendRequestHeaders += OnPreSendRequestHeaders;
    }
    public void Dispose()
    {
    }
    void OnPreSendRequestHeaders(object sender, EventArgs e)
    {
      HttpContext.Current.Response.Headers.Remove("Server");
      HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
      HttpContext.Current.Response.Headers.Remove("X-SharePointHealthScore");
      HttpContext.Current.Response.Headers.Remove("SPRequestGuid");
    }
 }
}

4. Save the file
5. Edit the web.config file of the SharePoint web application
- Add the custom module to the section system.webserver
- have the custom headers removed

<system.webServer>
  <modules runAllManagedModulesForAllRequests="true">
    ...
    <add name="CustomHttpModule" type="Custom.ServerModules.CustomHttpHeaderModule" />
  </modules>
  ...
  <httpProtocol>
    <customHeaders>
      <remove name="MicrosoftSharePointTeamServices" />
      <remove name="X-Powered-By" />
    </customHeaders>
  </httpProtocol>
</system.webserver>

One remark though if you implement this. Removing the header MicrosoftSharePointTeamServices may break your search crawling. In my case I usually dedicate a web front end for crawling or have the Web application role activated on the crawler. Evidently this web front end does not get the custom httpmodule.

Getting rid of “Could not find stored procedure ‘dbo.Search_GetRecentStats’” error

another one of those errors that can appear in your ULS logs which can easily be solved. This error also logs events in the Application eventlog with ID 6398 and 5586.

I found the solution to this issue on the SharePoint forum here

This happens when you have the Usage and Health Data Collection Service Application installed. This service application creates a database just for logging. Apparently the Search Service was trying to make entries in that database and couldn’t.

The solution to this issue is to enable the Usage Data Collection, which is not enabled by default when you create the Usage and Health Data Collection Service Application .

To enable the Usage Data Collection navigate to Central Admin\Application Management\Service Applications\Manage service applications. Once there highlight the WSS_UsageApplication (or whatever name you gave the service application)and select manage from the ribbon. Under Usage Data Collection check the box. Under Health Data Collection check the Enable health data collection box. Hit OK and the errors will be gone.

Where is the RSS Viewer web part in SP 2010?

Like everything in SharePoint why make things simple if you can make it hard :)

Turns out that if you want the RSS Viewer webpart, you need to activate the “SharePoint Server Standard Site Collection features” feature in your site collection first.

Took me about 10 minutes of snooping around in the Web part gallery and trying ta add a new one, before I figured that one out.

Thanks to Craig Lussier for answering this exact question on the Technet Forum.

Fixing the Usage and Health Data Collection Service Application Proxy (By Tristan Watkins)

Unfortunately in every farm that I have provisioned so far using powershell I keep running into this issue that the Usage and Health Data Collection Service Application Proxy is set to Stopped.

The fix that Tristan Watkins describes on his blog here fixes just that.

Commands:

#Run Get-SPServiceApplicationProxy to enumerate the IDs of all the Service Application Proxies in your farm.
DisplayName          TypeName             Id
-----------          --------             --
State Service App... State Service Proxy  e51696f1-3523-4e20-9b75-578485024b37
Managed Metadata ... Managed Metadata ... 830bafcf-f0d3-4254-91e4-8cfe11840e27
Search Service Ap... Search Service Ap... a988d821-8247-4294-ba11-961b22e51f8b
Application Disco... Application Disco... af617d69-7332-49f3-a61c-0eef3f7470cf
Excel Services Ap... Excel Services Ap... b6c5b951-7b4d-4837-83f3-c916c1ef6c7d
WSS_UsageApplication Usage and Health ... 83301455-c854-4596-af5c-0bc6ee963b6d

#Copy the ID for the WSS_UsageApplication.
$UP = Get-SPServiceApplicationProxy | where {$_.ID -eq "PASTE ID HERE"}
$UP.Provision()

If you refresh the Manage Service Application page the proxy should be started now.

Provision SharePoint 2010 Search with custom database names

I’m more of a mitliple scripts guy for configuring my SharePoint 2010 farms than a 1 humongous script guy that does everything. I prefer to use one script for installing my binaries and creating/joining the farm and then several scripts for configuring specific service applications. I find it easier for troubleshooting.

Anyway, here is the script I created based on the AutoSPInstaller for configuring the Search Service Application using custom database names:


$SSADB = "SharePoint_ServiceDB_SearchAdmin"
$SSAName = "Search Service Application"
$SVCAcct = "CONTOSO\the_search_service_account"
$SSI = get-spenterprisesearchserviceinstance -local

# 1.Start Services search services for SSI
Start-SPEnterpriseSearchServiceInstance -Identity $SSI

# 2.Create an Application Pool.
$AppPool = new-SPServiceApplicationPool -name $SSAName"-AppPool" -account $SVCAcct

# 3.Create the SearchApplication and set it to a variable
$SearchApp = New-SPEnterpriseSearchServiceApplication -Name $SSAName -applicationpool $AppPool -databasename $SSADB

#4 Create search service application proxy
$SSAProxy = new-spenterprisesearchserviceapplicationproxy -name $SSAName"ApplicationProxy" -Uri $SearchApp.Uri.AbsoluteURI

# 5.Provision Search Admin Component.
set-SPenterprisesearchadministrationcomponent -searchapplication $SearchApp -searchserviceinstance $SSI

This will just create your required databases. From this point on you can configure the required crawl / query topologies using Central Admin.