Adventure in SPWonderland

Take apart and put back together


Update User Emails in SharePoint from Active Directory


With SharePoint once a user is added to a SharePoint site the users email is saved at that point in time and only updated if you have the User Profile Service setup and running in which case a timer job updates user information in all site collections in the Farm.

Sometimes farms are created that stand alone and do not have the User Profile service setup or it might be a foundation Farm which has no User Profile Service. In that case this script might be useful.

It gets the Email address from AD for every user in all site collections within a Web Application and updates it if needed.

From a Powershell prompt

To Report on out of date  user emails
  .\FixUserEmails.ps1 http://sharepointurl

To update emails 
  .\FixUserEmails.ps1 http://sharepointurl $true


Should work for 2007 and 2010.

Its not guaranteed to work across multiple domains as the sAMAccountName attribute does not contain the domain, otherwise let me know of any issues. (2.82 KB)

PowerShell quickie: Extract the feature IDs used in large SharePoint projects

You know how it is, you start developing a project and then 6 months later you look back and realise you have to document everything you've produced.

I've just gone through that process and need a quick list of all the features ids scattered around various subdirectories of a large project.


<Feature  Id="886f12cf-97ca-4789-baf8-6f13f9f2cedf"
          Title="PGPSO Contract Management Project Upgrade"
          Description="Feature that upgrades Project Sites for Contract Management."
          ReceiverAssembly="PGPSO_CM_Project_Upgrade, Version=, Culture=neutral, PublicKeyToken=aa0408b86137366a"

Firing up Powershell navigating to the root of the solution folders and running this command gets me the list

gci -recurse -filter  feature.xml | % { $contents=get-content $_.fullname; $x=[XML]$contents; "{0} {1}" -f $x.Feature.Id, $x.feature.title }



gci is an alias for get-childitem which allow you to recurse subfolders and provide a filter parameter. Then use get-content to open the file, convert to an XML object and then directly reference the Id and title of the feature.xml file.



Changing ODC links in Excel Services from code

One of my coworkers on a current project has posted a useful entry about fixing a problem you will have when deploying Excel files into Excel Services across multiple farms that use connections in external ODC files. The fix is to use crack open the excel file using OpenXml and change the URL to the ODC link. Nice one Oriol. Details here

Full Text Searching your CS and PowerShell code with SharePoint Search



Recently I went through the process of indexing a subversion source code repository with SharePoint. I thought I'd share those steps as OOTB SharePoint won't index ps1, cs or vb files.

Setting up search to index these files works either if the files themselves live in a document library or are external to SharePoint. The process to index files from other source control systems will vary depending on how you can get access to the source files. If you need to index SourceSafe you can set up what's called a mirror directory that automatically save the files from your repositories on disk and I suspect you can index Team Foundation Server via its Web Access URL's although I've not tried that.

The subversion side of things is pretty easy, pick the repository you want and export the latest version using the svn client i.e. svn export svn://devhosting/svn/webparts d:\SVNExport\webparts. Script the export of each repository and then schedule it.

On the SharePoint side you set up a new content source to crawl the directories.

In this case the Indexing is on a separate machine so we enter the UNC path. Make sure the content access account has read rights to the share. If needed you can setup separate credentials for this source.

In the SSP on the Search Setting page, click New Content Source under Content source and crawl schedules



The problem now is if you start a full crawl typically only the .txt files are indexed as the SharePoint indexers have no idea what to do with file extensions it doesn't recognise.

There are a couple of steps to getting new file extensions indexed. This assumes you are a Search Service administrator.

First add the extension to File Types

1. On the Search Administration page, click File Types under Crawling.


2. On the Manage File Types page, click New File Type.


3. On the Add File Type page, type the file name extension in the File extension box for the file type that you want to add.
To search for PowerShell files, type ps1
Do not include the period (.) character in front of the file name extension.

4.Click OK.


5. Rinse and repeat for each file type that you want to add.

The second step in getting the file extensions recognised is to add it to the registry entries the SharePoint Server Search service reads when it starts up. This key is located at

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\12.0\Search\Setup\ContentIndexCommon\Filters\Extension

Add a new key, enter the extension including the dot i.e. .ps1.

Save and set its default value to be {4A3DD7AB-0A6B-43B0-8A90-0D8B0CC36AAB}. This means use the text parser Ifilter tquery.dll for this extension.


And a new key for each file extension you want indexed in this case cs,ps1 and aspx but you can add vb vbs or whatever other text files you need indexed.

Stop and start the search service with these commands

net stop osearch

net start osearch

Now do a full crawl of your content type and your files should have been full text indexed. The crawl log is useful in seeing if the filtering barfed on your files.


Now you can go to the Search Center enter your keyword and get a list of code files back.


Here I've set up a custom scope, search page, and added a custom search tab so separate the code results on its own. I won't go into it here but there is a good post here that shows how you do this.

Even better with SharePoint Search if you know you want PowerShell files only you can enter the fileextension keyword and search will filter out everything but PowerShell files.



Searching your entire code repository with subsecond query times is now pretty easy.

UK Community Day at Microsoft Reading

The UK Microsoft User Groups have organised another huge gathering at Microsoft Reading next week.

This time it's split over 2 days April 8th and 9th and features a lot of great sessions. User groups that I'm active in such as the UK SharePoint user group, PowerShell user group and the Vista squad will be there along with the user groups for Exchange, SQL Server and others.

It's not often you get a host of experts on these subjects in one location so check out the agenda and see if any sessions take your fancy.

I'm doing a session on day 2 crossing over two groups SharePoint and PowerShell on moving data in SharePoint using the Content Deployment API (aka Prime API) and PowerShell. I'll go through some of the functions and cmdlets I've written to make moving data easier, samples include moving list items, lists, webs and site collections within and between farms.

Fix: Getting the Silverlight Blueprints for SharePoint to work

I'm doing a presentation tonight for SUGUK on Silverlight in sharePoint and wanted to demo some of the Silverlight Blueprints for SharePoint.

Naturally I hit a few issues along the way so I thought I'd pass a few tips on.

A major requirement is to have .Net 3.5 and AJAX running on your SharePoint site. If you configure AJAX by hand as I did check this MSDN article for configuring AJAX but use as the version number.

I configured AJAX by hand but there is also a CodePlex feature that can install AJAX on all your WFE.

It will also help to have Visual Studio 2008 and the Silverlight SDk installed on your dev box.

The first issue is that none of the XAP's as shipped will work on my machine. You'll get an error like this



checking the XAP files shows the shipped one has this as the first line of the manifest.

<Deployment xmlns="" xmlns:x="" EntryPointAssembly="SL.XAML.Navigation" EntryPointType="SL.XAML.Navigation.App">

but if I recompile the source I get

<Deployment xmlns="" xmlns:x="" EntryPointAssembly="SL.XAML.Navigation" EntryPointType="SL.XAML.Navigation.App" RuntimeVersion="2.0.30226.2">

The missing RuntimeVersion seems the key here, looks like the U2U folks were running a slightly different build of chiron the XAP compiler and certainly the Silverlight 2 runtime on my machine wont run a XAP without it.

So the fix is to recompile the Silverlight Applications and redeploy the XAP to the ClientBin directory in your IIS website directory.

Second and more bizarre is the Navigation Sample. If you try to run it you get an error about being unable to load the Assembly.

The problem here is that the PublicKey for the SL.Controls.Navigation.Dll is wrong in the MasterPage.



The MasterPage has 4aec304184eb9a69 when the DLL has bb99f30c0098259c.

The Fix is to change the MasterPage Register TagPrefix line to bb99f30c0098259c. You can use SharePoint Designer or uninstall the feature change it and then reinstall, reactivate.

This will happen when you dev with an internal snk file which has your company private keys in it and then decide you've got to change it before you ship. I've done exactly the same thing myself, it really helps to test it on a single machine outside your company first.



PowerShell: Generating a proxy for all the SharePoint WebServices

Zach Rosenfield has a nice post on calling WebServices from PowerShell. The steps are pretty simple: generate a proxy cs file, compile it into a DLL and then load that DLL up into Powershell AppDomain.

Well I've been doing some work with quite a few of the WebServices and I wanted to compile all the proxys into a single DLL.

Use Zach's post to setup the PowerShell environment variables needed to call the Visual Studio SDK utilities wsdl.exe and csc.exe

Heres the script to compile all the available SharePoint Webservice's into one DLL.

It simply enumerates all the ASMX files in the ISAPI directory and passes each item in that list to WSDL.exe which generates the proxy cs files.

You need to change the URL in this script to point to a valid SharePoint site and make sure there are no other .cs files in the directory before running this script.

$asmxlist= dir "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI" *.asmx | select name

$asmxlist | foreach-object {
write-host "Generating SharePoint Proxy Library for $($" -foregroundcolor green 


wsdl "$($" /o:$outputfilename /namespace:$namespace


write-host "Compiling SharePoint Proxy Library" -foregroundcolor green 
csc /t:library /out:FlexnetConsult.SharePoint.WebServices.dll *.cs 


So the output should be something like this




Now three of the WebServices generate an error SlideShow.asmx. FormserverProxy.asmx and contentareatoolboxservice.asmx but as I'm unlikely to use them I'm not going to worry about those.

So now we have a DLL called FlexnetConsult.SharePoint.WebServices.dll in our directory that we can use to call the (almost) any SharePoint Web Service.

I've attached the compiled dll and script.

In my next post I'll use the DLL to do something I've wanted to do for ages and that's list, add and delete Web Parts on a page using PowerShell.

Now your probably shouting, hey why not just call the object model and GetLimitedWebPartManager, yep but that doesn't work as without a web.config and possibly a HttpContext all you get back are Error WebParts as the WebPart safecontrollist cannot be accessed.



SharePoint bug: URL Protocol prompts for anonymous users

There is an issue outstanding in WSS that is causing a few of the people who download our free Flash Web Parts grief. 

The issue shows up when anonymous users hit a web page with our Web Parts on it and they get authentication prompts.

I've gone into detail into how we get SharePoint data into flash here. We call owssvr.dll via HTTP get, pass it some parameters and get the xml data back. Great, this has been around and working since 2001. Unfortunately in WSS 3 (and MOSS) an authentication request is sent back for anonymous users even if all the settings are configured correctly. SP1 doesn't fix this either.

The issue has been open with PSS since late last year with no progress. Another conversation this week assured me this be actioned..still waiting.

Its a dismal situation and I apologise to anybody who has wasted time on trying to get our Web Parts to work.

I'm trying not to think about the resources been expended on Office 14 when issues like this remain outstanding.