PowerShell–Rename the ‘&’ in File Names

So recently I was moving large amounts of .DOC files into SharePoint libraries and it was occasionally causing an error due to invalid characters in the file name.  This was mostly due to having abbreviations in the names that included ampersands, for example “M&A Report 2010.doc”.  Now, looking at this, it’s an easy fix to replace the ‘&’ character with an underscore with PowerShell, this example does it for all files in a directory:

get-childitem *.* | foreach { rename-item $_ $_.Name.Replace("&", "_") }

Which works fine for the files within that folder, what if you want to do it recursively and include the subfolders?  no problem for PowerShell thanks to the ‘-recurse” flag:

get-childitem *.* -recurse | foreach { rename-item $_ $_.Name.Replace("&", "_") }

And there you have it, an easy and simple way to prep a file share or set of directories to move into a SharePoint library.

SharePoint 2010–Mobility Redirect Feature

SharePoint provides a clumsy support for mobile devices by providing for List Views designated for mobile devices and automatic page redirect if the site is accessed by a mobile device.  By rendering column data in a format suitable for mobile devices it works, but it’s not a great experience in my opinion. By default Windows SharePoint Services ships with a “Mobility Redirect” feature that creates a default.aspx page in the /m folder of each site.

For supporting users who what to access a mobile friendly version of the site, You have two ways to turn on the feature:

Using stsadm.exe command line tool

Stsadm -o activatefeature -name MobilityRedirect -URL “http://<URL>” 

Using PowerShell

Enable-SPFeature -Identity MobilityRedirect -Url http://<URL>

Remember that this is a SPWeb feature so you can turn it Off or On on an individual site.  Personally I don’t like the branding on the mobile view, so remember that when branding or developing sites for mobile devices, you can easily switch to mobile view of the page by using User Agent Switcher add-in for FireFox.

Replicating User Profile Data in SharePoint 2010

Having recently upgraded and migrated one of our farms from the old datacenter running 2007 to the new datacenter running 2010 there were some slight issues with the User Profiles and getting them moved to the new location.  Within SP2010 there are generally only two ways to get user profile data onto the new farm from an existing farm in SharePoint 2010. The first is to consume the User Profile Service of the host farm, but this causes issues if you want to host a My Site host (that contain personal sites) on the consuming farm. The second way is to use the Replication Engine. The Replication Engine uses audiences and trusted My Site Hosts to determine which farm “owns” the particular set of user profile data. The Replication Engine can also be used to keep data in synch with SharePoint 2007 data, which in our case was a good thing since we had to leave some sites behind on the 2007 farm until such time that we can update the custom coded web parts to be 2010 compliant.


  1. Backup your Profile database.
  2. Download the SharePoint 2010 Administration Toolkit http://www.microsoft.com/downloads/en/details.aspx?FamilyID=718447d8-0814-427a-81c3-c9c3d84c456e&displaylang=en and install it on at least one server. If you want to push data in more than one direction you will need to install it on another server in the other farm as well.  I generally like to use the server we’ve set up for central admin or an application server and stay off the WFEs.
  3. Backup your Profile database.
  4. Create your audiences and Trusted My Site Host entries on all the servers involved.  If they’re not set up correctly you get lots of fun error messages which are typically MSCryptic.
  5. Backup your Profile database.
  6. Read the User Profile Replication Engine Overview at http://technet.microsoft.com/en-us/library/cc663011.aspx. The 2010 version is a PowerShell window with a few commands. Basically you can start and stop incremental replication, do full replications, and get a list of profile properties, because PowerShell is awesome that way.
  7. Backup your Profile database.
  8. Before you start replicating…turn off the smtp service, full replications will send out colleague notifications, which is not fun to try to explain to everyone why they got a bunch of notification for stuff they already had.
  9. Just for good measure, Backup your Profile database

A couple of points to remeber when trying to run a profile replication in SharePoint 2010.

  • The account running the replication needs the ‘Full Control’ permission on the User Profile Service Application on the destination SharePoint farm.
  • Although the documentation states that the URLs to use for the source and destination should be those of the my site host on each farm, I could not get it working using these URLs at all. Instead, the URLs for the Central Admin site (!) on each farm worked a treat. These values are running the Start-SPProfileServiceFullReplication or Start-SPProfileServiceIncrementalReplication cmdlets.
  • Again, the documentation implies that you should pass in the Properties to the replication cmdlet, either explicitly or via the pipeline (well, all the examples I could find did). I found this to be troublesome, and it is an optional parameter so try the most simple call to the replication cmdlet – if the User Profile Service on the source farm is customised, this seemed to cause issues if trying to replicate fields that don’t exist on the destination.

SharePoint 2010 – Migrating Search Admin to Different Servers in the Farm

Recently one of the farms I work with got some additional servers joined to the farm. Rather than provisioning another WFE, we were expanding some of the back-end capacity. The Search Admin was running on a WFE, and we wanted to move search off to some dedicated servers. Here is the PowerShell script for moving Search Admin:

$SSA = Get-SPEnterpriseSearchServiceApplication "Current Search Service App"
$SA = Get-SPEnterpriseSearchAdministrationComponent -SearchApplication $SSA
$SA | Set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance NewServerName –Force

After moving the Search Admin you’ll want to kick start the crawlers with the following:

Suspend-SPEnterpriseSearchServiceApplication $SSA
Resume-SPEnterpriseSearchServiceApplication $SSA

And as easy as that you can move search admin off to a new server!

SharePoint 2010–Blocked File Types

SharePoint has a nice little security feature for blocking certain files from being uploaded to SharePoint libraries because of security issues. Each Web application maintains a list of blocked file types that is based on file name extensions. For example, you can block files that have the .exe extension because those files can be run on the client computer and can contain malicious code. I was asked a question the other day about blocked file types in SharePoint 2010 and how to allow them into a SharePoint repository. Now I realize that this is a massive risk but the client had a reason for wanting to do this because they wanted to store installation packages in a SharePoint library. This is generally considered not best practices, but if you have a site that is trusted and only a few individuals have upload rights, you are effectively creating a network share for installation packages.

However, I will stress that you should never allow any executable file in your SharePoint site. But…there is an exception to every rule and this is probably one of them.

Using SharePoint 2010 Central Admin

First navigate to Central admin and once there click on the security section


Once in the security section you need to be in General Security | Define blocked file types


Here you will find a list of file with file type extensions just add or remove the files you wish to block or unblock and then click ok. This is a global setting across all site collections so happy blocking. And don’t forget to check and tighten up on the media files including WMA, MP3, MP4, MOV, WMV etc. it will save you gigabytes of storage later.


Using PowerShell Commandlets



function Get-SPBlockedFileType {
 This function can be used to retrieve blocked file types for a SharePoint Web Application.
 This PowerShell function uses the SharePoint Object Model to get all file
 types in the BlockedFileExtensions property for a Web Application.
 C:\PS>Get-SPBlockedFileType -WebApplication http://intranet
 This example gets blocked file types for a SharePoint Web Application at http://intranet.
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
$WebApp = Get-SPWebApplication $WebApplication
$Extensions = $WebApp.BlockedFileExtensions
$Extensions | ForEach-Object {Write-Host $_}


function Add-SPBlockedFileType {
 This function can be used to add a blocked file type for a SharePoint Web Application.
 This PowerShell function uses the SharePoint Object Model to add file
 types to the BlockedFileExtensions property for a Web Application.
 C:\PS>Add-SPBlockedFileType -WebApplication http://intranet -Extension ps1
 This example adds the ps1 file type to the BlockedFileExtensions collection
 for a SharePoint Web Application at http://intranet.
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
$WebApp = Get-SPWebApplication $WebApplication
$Extensions = $WebApp.BlockedFileExtensions


function Remove-SPBlockedFileType {
 This function can be used to remove a blocked file type from a SharePoint Web Application.
 This PowerShell function uses the SharePoint Object Model to remove file
 types from the BlockedFileExtensions property for a Web Application.
 C:\PS>Remove-SPBlockedFileType -WebApplication http://intranet -Extension ps1
 This example removes the ps1 file type from the BlockedFileExtensions collection
 of a SharePoint Web Application at http://intranet.
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
$WebApp = Get-SPWebApplication $WebApplication
$Extensions = $WebApp.BlockedFileExtensions
$Ext = $Extensions.Remove($Extension)
if($Ext -eq $true){
Write-Warning "Filetype $($Extension) has been removed from Web Application $(($WebApp).Name)"
Write-Warning "Unable to delete filetype $($Extension) from Web Application $(($WebApp).Name)"


Using Visual Studio 2010:

  • Open Visual Studio 2010.
  • Go to File => New => Project.
  • Select Console Application from the installed templates.
  • Enter the Name and click Ok.
  • Add the following references.

    o Microsoft.SharePoint.dll
  • Add the following namespaces.

    o using Microsoft.SharePoint;

    o using System.Collections.ObjectModel;

  • Replace the code with the following.

    string webAppUrl = "http://<server>/";

    string addBlockFileType ="aspx";

    string removeBlockFileType ="asp";

    SPWebApplication webApp =SPWebApplication.Lookup(new Uri(webAppUrl));

    Collection<string> blockFileTypes = webApp.BlockedFileExtensions;

    foreach (string fileExtension in blockFileTypes)


    // displaying all the file extensions that are blocked




    // adding blocked file type


    // removing blocked file type



  • Build the solution.

  • Hit F5.

  • All the file extensions from the blocked file type will be displayed as shown in the following.


  • A new file extension "aspx" is added and the existing file extension "asp" is removed successfully.

Default Blocked File Extensions

The following table shows the file types that are blocked by default and their corresponding file name extensions.

File name extension File type


Microsoft Access project extension


Microsoft Access project


Application file


ASP declarations file


ASP.NET Web handler file. Web handlers are software modules that handle raw HTTP requests received by ASP.NET.


ASP.NET Web Services source file


Active Server Pages


Microsoft Visual Basic class module


Batch file


Compound index


Certificate file


Compiled HTML Help file


Java class file


Microsoft Windows NT command script


Microsoft MS-DOS program


Configuration file


Control Panel extension


Security certificate


Script file


Windows dynamic-link library




Microsoft Visual FoxPro compiled program


Help file


HTML program


Script file


HTML document


Internet Information Services file


Internet database connector file


Internet data query file


Internet Naming Service


Internet Communication settings


Internet Document Set file


JScript Encoded script file


Korn Shell script file
















Microsoft Access stored procedure










Microsoft Access add-in program


Microsoft Access program


Microsoft Access MDE database


Microsoft Access data file


Microsoft Access workgroup


Microsoft Access wizard program


Microsoft Common Console document


Microsoft Agent script helper


Microsoft Agent script helper


Microsoft Agent script helper


Microsoft Agent script helper


Microsoft Agent script helper


Microsoft Agent script helper


Microsoft Windows Installer package


Windows Installer patch package file


Visual Test source files


Microsoft Office profile settings file


Photo CD image or Microsoft Visual Test compiled script


Shortcut to MS-DOS program


System file


Program source file


Printer file


Microsoft Outlook personal folder file


Registration entries


ACT! database maintenance file


Windows Explorer command file


Screen saver


Script file


Windows shortcut


Shell Scrap object


HTML file that contains server-side directives


HTML file that contains server-side directives


Simple Object Access Protocol file


HTML file that contains server-side directives


Uniform Resource Locator (Internet shortcut)


Microsoft Visual Basic Scripting Edition file


VBScript Encoded Script file


VBScript file


Windows Script file


Windows Script Component


Windows Script file


Windows Script Host settings file