Archive for June, 2012

Moving SharePoint 2010 Site Collections Between Managed Paths using PowerShell

June 26, 2012 4 comments

Moving Site Collections between Managed Paths in SharePoint 2010 is a two to three step process.  I wish It was as simple as moving a Site Collection between content databases, which basically is a one line PowerShell script.  Granted its not very hard to move between Managed Paths it just takes time depending on the size of your Site Collection.  If its a rather large Site Collection it can take some time to move.

Below is the script to successfully move a Site Collection between Managed Paths.  Microsofts Best Practices is to have less than 20 Managed Paths in a given Web Application, having more will affect system performance.  In my current environment I had 25 Managed Paths in one dedicated Web Application (that was to much) so I needed to move these Site Collections from their explicit Managed Path to a wildcard managed path i.e (/sites/) instead.

Before you get started make sure your managed path you want to move to already exists.  I will update this script later to ask the user if they want to create a managed path before moving.

#Get the from Site Collection URL
$fromURL = Read-Host “Site Collection To-Move URL”
#Get the to Site Collection URL

$toURL = Read-Host “Site Collection Move-To URL”

#This is not necessarily needed, I did this just in case you want your Site Collection to live in the same database after the move, in most cases the Site Collection will be placed back into the same DB.
$Database = Get-SPContentdatabase -Site $fromURL

#Location to the backup file directory to store Site Collection backup files
$backupPath = Read-Host “Location you want to save backup files”

#Backing up Site Collection prior to moving
Write-Host “Backing Up Site Collection….”

Backup-SPSite $fromURL -Path $backupPath -force

#Removing Site Collection from old managed path
Write-Host “Removing Site Collection from old managed path location…”

Remove-SPSite -Identity $fromURL -Confirm:$false

#Restoring Site Collection to new Managed Path
Write-Host “Restoring Site Collection to new managed path location…”

Restore-SPSite -Identity $toURL -Path $backupPath -Confirm:$false

#Remove backup files from the backup dirctory
Remove-Item $backupPath

#Remove Managed Path from Web Application
$removeManagedPath = “Name of Managed Path to Delete”
Write-Host “Deleting $removeManagedPath managed path”
Get-SPWebApplication | Remove-SPManagedPath $removeManagedPath -Confirm:$false


Getting a List of All Checked-Out Files with No Checked-In Versions in SharePoint 2007 Using PowerShell

June 21, 2012 1 comment

I needed to generate a list of all documents that were checked out but never had a checked-in version.  I needed to do this for a few Site Collections in my MOSS 2007 Farm.  Thanks to Gary LePointe he has already done the hard work for us.

I basically just took his script which works great in SP2010 and modified it a little to work with MOSS 2007

Please see script below.

**UPDATE** — The 1st Script below only returns documents that are checked out, not documents that are checked out with no checked in version.

**See script 2–the one below this one to get a report of all checked out documents with no checked in version**

—————————Get All Checked Out Documents———————————————————————————————————-

[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

$site=New-Object Microsoft.SharePoint.SPSite($siteURL)

function Get-CheckedOutFiles()
    foreach ($web in $site.AllWebs)
        Write-Host “Processing Web: $($web.Url)…”
        foreach ($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]}))
            Write-Host “`tProcessing List: $($list.RootFolder.ServerRelativeUrl)…”
            foreach ($item in $list.CheckedOutFiles)
                if (!$item.Url.EndsWith(“.aspx”)) { continue }
                $hash = @{
                    New-Object PSObject -Property $hash
            foreach ($item in $list.Items)
                if ($item.File.CheckOutStatus -ne “None”)
                    if (($list.CheckedOutFiles | where {$_.ListItemId -eq $item.ID}) -ne $null) { continue }
                    $hash = @{
                        New-Object PSObject -Property $hash

Get-CheckedOutFiles | Out-GridView


———————–Get All Checked Out Documents with no Checked In Version—————————————

[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

function CheckedOutItems()
    $url=Read-Host “Please Enter In Site Url”
    “SiteURL ‘t” + “FileName ‘t” + “CheckedOutTo ‘t” + “ModifiedDate ‘t” + “Version” >> c:\temp\checkedoutfiles.csv
    $site = New-Object Microsoft.SharePoint.SPSite($url)
    $webs = $site.AllWebs
    foreach($web in $webs)
        foreach($list in $listCollections)
            if($list.BaseType.ToString() -eq “DocumentLibrary”)
                $items = $dList.Items
                $files = $dList.CheckedOutFiles
                foreach($file in $files
                    $web.Url + “‘t” + $wuse + “‘/” + $file.LeafName + “‘t” + $file.CheckedOutBy.Name + “‘t” + $file.TimeLastModified.ToString() + “‘t” + “No Checked In Version” >> c:\temp\checkedoutfiles.csv



Fixing Error: The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information, contact your server administrator.

June 19, 2012 1 comment

Recently my SharePoint 2010 farm crashed.  Well just one server (index/CA Server), and then it was just the domino effect afterwards.  Luckily it was not the SQL Server so all my data files were still accessible/recoverable.  Since there were a lot of things going on behind the scenes of SharePoint with unexplained errors, and random things not working the decision to rebuild the farm was the direction I wanted to take to elevate majority of the problems.

So since I usually do everything via PowerShell, It was very simple to remove/add servers to the SharePoint farm and reconfigure, and since I already had all my data files (content dbs, service application dbs, search dbs, etc) It was very easy to get things back to a “stable” state.

Using PowerShell I reconfigured all the Service Applications over again pointing them back to their data files, however their are a few Service Applications that “bitch” about “used” databases.  One of those services is the Server State Service.  When I tried to reconfigure this Service Application via PowerShell it complained that the database was not empty, and it spit out that ugly red message we love to see when things go wrong.

However, I paid it no mind and told myself I would just configure it later since it’s not a show stopper.

Well today when a customer was trying to add a InfoPath Form Web Part onto their Site they were receiving this error:

“The form cannot be rendered.  This may be due to a misconfiguration of the Microsoft SharePoint Server State Service.  For more information, contact  your server administrator.”

Whoops…I forgot to go back and reconfigure Server State Service after rebuilding the farm.

The State Service is a shared service that is used by some Microsoft SharePoint Server 2010 components to store temporary data across related HTTP requests in a SQL Server database. In SharePoint Server 2010, the State Service is required by InfoPath Forms Services (including out of the box and custom workflow forms), the SharePoint Server 2010 Chart Web Part, and certain Microsoft Visio 2010 scenarios that do not use Microsoft Silverlight 3.

Now there are two ways to reconfigure the Server State Service.   You cannot configure it via Central Administration.

One way is to simply run the configuration wizard.  The second way is via PowerShell.

Since I like PowerShell I will use that, and plus running the wizard will interrupt SharePoint.

Below are the steps to follow to reconfigure the Server State Service.
For my case since I already had a database for Server State Service and I wanted to reuse that same DB name I had to delete the existing DB, or change its name on the SQL Server.   If this is the first time you are configuring Server State Service you don’t have to worry about the DB steps.

1. Open up SQL Server, find the ServerStateDB, right click and delete DB (this will prevent PS from laughing at you)
2.  Next open up SharePoint Administrator Shell (PowerShell) as Administrator
3.  Type: $serviceApp = New-SPStateServiceApplication -Name “State Service”
4.  Next:  New-SPStateServiceDatabase -Name “StateServiceDatabase” -ServiceApplication $serviceApp
5.  Then: New-SPStateServiceApplicationProxy -Name “State Service” -ServiceApplication $serviceApp -DefaultProxyGroup

This will provision the State Service Application.

Go back to the site where you were receiving the error:

“The form cannot be rendered.  This may be due to a misconfiguration of the Microsoft SharePoint Server State Service.  For more information, contact  your server administrator.”

The error should be gone, and the page or web part should render okay on the page.

Removing a Corrupted Site Column in SharePoint 2010

June 7, 2012 15 comments

After migrating a Site Collections content data from our SP2007 environment to our SP2010 environment using Metalogix we ran into some problems with lists that did not allow us to open/update/edit/ or add new items.  We would receive this error: “Field type xxx is not installed properly. Go to the list settings page to delete this field.”

To determine what field is causing the error run this PowerShell script.  The PowerShell should terminate with an error, along with the name of the erroneous field.

$web = Get-SPWeb http://portal/site
$fields = $web.Fields
foreach ($field in $fields) {write-host $}

This script will loop through all the field types.  You should receive an error similar to this:

For our case there was a problem with Visual Fusion and it was  a Field Type of VFSLayerParams that was corrupted.  So for our case instead of ‘Field type Bool is not installed properly’.  It read ‘Field type VFSLayerParams is not installed properly’.

There is no way (that i’ve found) to remove the corrupted column via PowerShell or through UI SharePoint Designer.

The only way to remove a corrupted column is through the unsupported Microsoft way by directly deleting the column using a TSQL query on the content database itself or by completely deleting the Site Collection and starting over.

Since directly doing any type of edits on a SharePoint content database especially on a production environment will result in a non supportive state from Microsoft the best approach is to immediately open up a case ticket with Microsoft to cover your tail.

There has already been a case opened up that touches on this issue (Case #111090871991452).  I opened up one myself just to be covered.

Once the case is opened and Microsoft is aware of you making direct modifications to the databases you can proceed, or if you simply don’t care if you lose Microsoft Premier Support then you can go ahead and edit the database without opening up a case.  It’s up to you.

Okay now onto the steps.  Before you Proceed. I’M NOT RESPONSIBLE FOR YOUR FARM, so follow at your own risk.


First you will need to determine the GUID ID for the corrupted column.  To do this you will run a PS script against the Site Collection to generate a report that lists all the fields, like so.

$web = Get-SPWeb http://portal/site
$web.AvailableFields.SchemaXml | Out-File c:\temp\fields.txt

Once done open up the fields.txt file and do a search for the corrupted column.  So for my case I searched for (VFSLayerParams).

Once you find the column name, usually to the left you will find the field type GUID.

Copy the GUID down i.e. (a7756826-0a2c-45cd-a8f0-d891f236b388).  Actually you only need the last part of the GUID (d891f236b288)

Next you need to determine the Content Database this site collection lives in.  To do this you can visit Central Administration.

Central Administration -> Application Management -> View All Site Collections

This will list the Site Collection and the database it resides in.

Now that you know the Database Name time to head over to the SQL Server.

Once on the SQL Server Open up SSMS.

1.  Open up SSMS and open up a new Query against the Content Database that has the corrupted column
2.  Next select all the corrupted columns by field id GUID by running this TSQL query

SELECT * FROM [ContentDBName].[dbo].[ContentTypes] WHERE Definition Like (%d891f236b288%)

3.  This list all the columns in the Site Collection that are corrupted with that GUID
4.  Next it’s time to delete, run the following TSQL query to delete the corrupted columns.

DELETE FROM [ContentDBName].[dbo].[ContentTypes] WHERE Definition Lilke (%d891f236b288%)

5.  Make sure the columns were deleted by re-running the Select statement, if no more records return the columns have been deleted, if more records return repeat step 4.
6.  Close out of SSMS and log off the SQL Server

Now when you try to open/update/edit/add an item to the List you should be able to with no errors.