Archive | PowerShell RSS for this section

SharePoint 2013–Not able to remove an app…

Earlier this year I was playing around with Apps in SharePoint 2013 and deployed a app on one of my developer sites. Now a few weeks ago I noticed this early app experiments and wanted to remove it again. I was logged in as my farm admin (which is also a sitecollection admin to the dev site) and clicked remove… This is what happened:


This confused me a little bit, I did as the friendly message told me, refreshed the page and tried again… same outcome.

Next idea which came to my head was to give it a try using Powershell which you can find described pretty good at TechNet.

When I tried to remove the app using Powershell I experienced an error telling me:


When I cracked ULS viewer open I got some more details

System.InvalidOperationException: The System Account cannot perform this action.   
at Microsoft.SharePoint.Administration.SPApp.RegisterTasks(SqlSession session, Guid originalAppInstanceId, Guid paramSiteId, ICollection`1 tasks, SPAppJobOperation operation, SPUser jobCreator)   
at Microsoft.SharePoint.Administration.SPApp.RegisterTasksAndDependencies(SqlSession session, ICollection`1 tasks, ICollection`1 dependencies, Guid siteId, Guid instanceId, SPAppJobOperation operation, SPUser jobCreator)   
at Microsoft.SharePoint.Administration.SPApp.InstallNoPermissionCheck(SPAppInstance instance, Boolean isUninstall, Guid siteId, SqlSession session, Guid contentDatabaseId, SPUser jobCreator)   
at Microsoft.SharePoint.Administration.SPApp.Install(SPAppInstance instance, SPWeb web, String oauthAppId, Boolean alwaysOverwrite, Boolean isUninstall)   
at Microsoft.SharePoint.Administration.SPApp.Uninstall(SPAppInstance instance, SPWeb web)   
at Microsoft.SharePoint.Administration.SPAppInstance.UninstallInternal(Boolean adminOperationMode)   
at Microsoft.SharePoint.Administration.SPAppCmdlets.UninstallSP

at Microsoft.SharePoint.PowerShell.SPCmdlet.ProcessRecord()

With this knowledge I checked the details of the app:


And found the app being owned by another user which I used for developing (and deploying) the app.


When I logged in with this account and tried to remove the app… it worked.




Cant get siteowner for readonly sites

This is something I stumbled across recently… I wanted to retrieve a specific type of sites and their owners, when I checked the output of my script I figured that some sites seemed not to have siteowners, which irritated me a little. So I went to Central Admin checked the sites in the “View all sitecollections” area and found owners assigned to the sites. After fiddling around with PowerShell I figured out that if your site is set read-only you cant retrieve the siteowner anymore.

In the below PowerShell window you can see that I get a site and retrieve the owner from it. After that I set the site to be read-only, when I now retry to retrieve the owner I don’t get any information back. Once I set the read-only mode to false again the retrieval of the siteowner is working as expected.

I noticed this behavior in a SharePoint 2010 environment first and reproduced it in a SharePoint 2013 environment (from which I took the below screenshots).


If you look at the site in SharePoint 2013 you will be notified about the read-only status of your site.


In my special case I worked around it by retrieving the sitecollection administrators as I just needed somebody to contact but if you are really looking for that owner (or secondary owner) you might want to put a little bit more logic to your scripts to handle read-only sites.

SharePoint 2013 Following sites not working

I found an interesting issue in one of my SharePoint 2013 environments related to following sites. When a regular user clicks on the “Follow” button displayed in the top right corner of the screen the user will get an error.


If you look into the ULS log you will find the following error:


SQL Database ‘Databasename’ on SQL Server instance ‘InstanceName’ not found. Additional error information from SQL Server is included below.  Cannot open database “Databasename” requested by the login. The login failed.  Login failed for user ‘Domain\Username’.

Interesting about this issue is, that the account which doesn’t have permission to open the database is the application pool identity of the portal webapplication in which the site lives which the user would like to follow.

The Mysites reside in a different webapplication then the site the user wants to follow.

After a little investigation I tried to set the “GrantAccessToProcessIdentity”  for the mysite webapplication for the applicationpool identity of the webapplication where the site the user want to follow resides in.

For that I used the below Powershell, which grants the account specified connect permissions on the database level. (This was also used in my previous blogposts “PowerPoint / Word WebApps–PowerPoint / Word WebApp cannot open this presentation / document” and “Excel calculation services–The Workbook can not be opened” to grant the proper permissions)

$webApp = Get-SPWebApplication “YourWebapp”


After running this I double-checked the permission of the database in SQL and found the permissions granted to the account as expected. When the user now tries to follow a site everything works as expected.


I don’t know if this is the proper way to solve this issue, I have encountered it only once due to the fact that it is still very early in the SP2013 implementation timeframe, I just wanted to share my experiences with this issue and will continue to keep my eyes open. If you experience the same problems please let me know.

One of a kind–Create a SharePoint 2013 Sitetemplate overview

If you are not living under a rock you might have noticed that SharePoint 2013 made its first appearance to the public a little while ago. I get asked a lot to demonstrate new features and the new sites or setup little playground environments where customers can play on.

To ease things up a little bit I have created a little powershell script which creates one site per site-template and also creates a html output where you can see the sites created and click the url.

All the sites get created in a dedicated content database which also gets created by the script.

Disclaimer: Of course you never… really never…did I say never ever??? just run scripts you find on the internet which you don’t understand… Don’t blame me for whatever happens. You are running these lines on your own risk.

Add-PSSnapin "Microsoft.sharepoint.powershell"

$templates = Get-SPWebTemplate
$url = "http://yourURL"
$siteadmin = "domain\user"
$contentdbname = "SharePoint2013_TemplateDemo"
$reportlocation = "c:/Templateoverview.html"

write-host -fore Green "Creating new Contentdatabase"
New-SPContentDatabase -Name $contentdbname -WebApplication $url 

foreach($template in $templates)
    $templateurl = $url +"/sites/"+ $template.title
    $templatename = $

    new-spsite -Url $templateurl -Template $templatename -OwnerAlias $siteadmin -ContentDatabase $contentdbname -ErrorVariable $err -ErrorAction SilentlyContinue 
    if ($err)
        write-host -fore red "An issue occured when creating site:" + $templateurl
         write-host -fore Green "A site based on template" $template.title "has been created successfully"
         out-file -FilePath $reportlocation -inputobject "<a href='$templateurl'>$templatename  $templateurl</a></br>" -Append


write-host "Find a clickable overview of all sites created by this script at:" + $reportlocation