André Krijnen


Powershell: Return SPWebTemplateNameByWebTemplateId

by on Nov.10, 2011, under Powershell, SharePoint 2010, SharePoint Foundation

Sometimes you it’s easy to script some stuff, and you redo some stuff. For example: You want to manually script your export-import action in SharePoint automatically.

Something you need by importing the site is the webtemplate before you can start the import. So, what you can do before deleting the site is to extract the WebTemplateId. The WebTemplate in $web.Url is not sufficient, because it doesn’t translate the correct Configuration.

So, what I’ve did is to use the WebTemplateId and get the according WebTemplate Name. And use it to create a SPSite.

function Get-SPWebTemplateNameBySPWebTemplateId($WebTemplateId)
    $templates = Get-SPWebTemplate | Sort-Object "Name"
    $templateValues | ForEach-Object {
        if($_.ID -eq $WebTemplateId)
            $templateName = $_.Name
    return $templateName

$templateName = Get-SPWebTemplateNameBySPWebTemplateId -WebTemplateId 53

Write-Host = $templateName

Above will return BLANKINTERNET#2

Leave a Comment more...

Feature Deployment SharePoint 2010 (List Instance and List Definition)

by on Nov.07, 2011, under features, General, maintenance, Powershell, SharePoint 2010, SharePoint Foundation

So I started out today debugging some weird issues regarding feature deployment. And well sometimes I don’t know why I get errors, but what’s new. So first of all, let’s start where to start.

cannot complete this action.please try again

Starting point:

A colleague of mine had written a feature for a customer of us, which worked perfectly. The customer had never issues like it should. After almost a year we (me, and the customer) decided to change the full Site Templates. Like a developer should do is making and changing the solution work. Well then comes the burden. After days of work, testing everything out the solution worked by me. (Owwh yeah, the known starting point: well on my computer it works).

So after deployment at the production server it didn’t work. I didn’t knew why, because everything should work like my notebook. The reason is simple, I had the same configuration, databases, etc. Well that didn’t work that out to.

So I thought well, let’s start fresh with new content databases from production. Ahh yes, there we go. Well, at my notebook it didn’t work either. Whoehoe, nice, we’ve got a good starting point for debugging.

Visual Studio 2010:

So I worked with Visual Studio 2010 and the deployed the feature again to debug. Well. Strangely, the solution worked after that. So Microsoft did some tricks while deploying. So I searched and called some people, yes on sunday. And telling me that Visual Studio 2010 is deploying asychronously. Yeah I knew that, but after a minute and some conversation telling that Powershell is deploying synchronously. Well that the trick I thought. So I decided to help my self out with some times, running the admin jobs, etc.

Even that didn’t worked out.

Go debugging old fashioned style: disabling Web and Site scoped features in the onet.xml.

After the first Web Feature (Deploying some List Instances and List Definitions) disabled the solution worked by powershell. I didn’t have a clue, but ohh well, I decided to change the ordering of the feature. Instead of List Definitions first, I decided to set the List Instances first. And you know what, It worked.

After enabling the Web Feature again, I could run the New Site creation perfectly.

Leave a Comment more...

Powershell: Update all Document Libraries with MajorVersionLimit and MajorWithMinorVersionsLimit

by on Jun.15, 2011, under blog, Powershell, SharePoint 2010

I had to write a Powershell script to run thru all sites in a Web Application to enable Versioning. As well Major as Minor versions. With of course a limit on Major and Minor versions.

Next script should do the trick:

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$siteURL = $args[0]
$site = Get-SPSite($siteURL)
foreach($web in $site.AllWebs) {
 Write-Host "Inspecting " $web.Title
 foreach ($list in $web.Lists) {
  if($list.BaseType -eq "DocumentLibrary") {
  Write-Host "Versioning enabled: " $list.EnableVersioning
  Write-Host "MinorVersioning Enabled: "  $list.EnableMinorVersions
  Write-Host "EnableModeration: " $list.EnableModeration
  Write-Host "Major Versions: " $list.MajorVersionLimit
  Write-Host "Minor Versions: " $list.MajorWithMinorVersionsLimit
  $list.EnableVersioning = $true
  $list.EnableMinorVersions = $true
  $list.MajorVersionLimit = 2
  $list.MajorWithMinorVersionsLimit = 5
  Write-Host $list.Title " is updated with MajorVersionLimit 2 and MajorwithMinorVersionsLimit = 5"


Leave a Comment :, , , , , , more...

Invalid features SharePoint 2010: Features due to a Failed, Missing, or Unsuccessful Activation SharePoint WSP

by on Oct.04, 2010, under features, Powershell, Programming, SharePoint 2010, SharePoint Foundation, Visual Studio 2010

Every developer has one of those days that everything goes wrong. You developed some feature, and you decided to change the namespace of the feature. For some reason or another SharePoint 2010 doesn’t handle this well, and even Visual Studio 2010 doesn’t know how to handle it. So you received a message that you allready activated a feature with the same Id you want to deploy? And you can’t revert it in someway?

Well I thought to use PowerShell to uninstall these spfeatures which I tried, but the message was cloud and clear, can’t uninstall feature, because feature isn’t found? Huh?? Why is that? Well I tried Get-SPFeature to retreive all the features I installed, and what did I see? My features standing in that list, so I tried to remove it by Id, and what happend? Can’t find feature by Id? Crap you would say? Well I used the WssAnalyzerTool from and managed to get all the failing features.

Then I tried to run the WssRemoveFeaturesTool from the same site, but what did you say? Even that tool couldn’t find that feature… Imagine that… So the last resort: yes the plain old fashioned stsadm. Did that work well, yes!! It worked more then you could think off.

stsadm -o disablefeature -Id -force ==> Operation completed successfully
stsadm -o Uninstallfeature -id -force ==> Operation completed successfully

So you think you can do everything with powershell, well sometimes you can, sometimes you can’t.

2 Comments more...

Powershell on Windows 7

by on Aug.02, 2010, under Powershell

I didn’t know that standard Windows 7 has Powershell installed. When I started powershell I noticed the V1 version in the menu bar, but this is not the real version. I didn’t know that until I did:


It shows the following information:

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\> get-host

Name : ConsoleHost
Version : 2.0
InstanceId : 880b266d-2931-4ff5-9ba8-181e3ecc5ab3
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : nl-NL
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace

Leave a Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!


A few highly recommended websites...