Useful Powershell commands

I was getting tired of always googling the same powershell commands so from now on I’am adding some of them here.

Task: Add .dll to assembly on Windows Server 2012

Set-location "C:\folder_with_dll\"
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish

Leave a comment

SharePoint 2013 – Whats new

This post contains a collection of some nice links that I found interesting for getting started on whats new on SharePoint 2013.

SharePoint 2013 for IT pros
Capabilities and features in SharePoint 2013 (Includes 30 min video to get you introduced to new features)

For Designers
Top 6 New Features for Designers in SharePoint 2013 (Randy Drisgill)


This documentation/post is preliminary and subject to change. Sounds familiar 🙂

Leave a comment

European SharePoint conference in february 2013 comes to Copenhagen

This year the European SharePoint conference comes to Copenhagens Bella Center.

It runs from 4-7th of february 2013

Read more here

Leave a comment

SharePoint 2013 Preview finally here

As you may already know SharePoint 2013 Preview is finally released.

SharePoint 2013 Preview can be downloaded here
View System requirements here

George Khalil (Sharepoint George) has made a detailed description on how to Install SP2013 in Windows Server 2012 with SQL 2012 in 2 parts here

I have installed my SharePoint 2013 virtual server on a VMWare workstation 8.0

Here are some quick steps on what and how I have installed.

  1. Windows Server 2012 Release Candidate must be installed first – oh really!
  2. Active Directory must be configured – I used this guide:
  3. SQL Server 2012 is next – remember to tick of Management tools so SQL Server Management studio is available
  4. I then followed George Khalil guide and prepared the system with the described service account
  5. And then installed SharePoint 2013 preview

You can also try and have a look at the Sharepoint 2013 preview via the Office 365 preview site:

Leave a comment

Funny call from Microsoft Support

Just thought I would share this.

I have recently been phoned by someone who claims to be from Microsoft Support Center, and telling me that they can se that my computer is infected with spyware and are running slow. The first time they called I didn’t have much time and since I was pretty sure it was a scam I waived them of when they could come with a believable story on how they could see info on how my laptop was running.

Yesterday they called again and I became curious on where it would go if I played along so I went on with there little scam and did what they told me… at the beginning at least… 🙂

First of all the english speaking (with indian accent) lady assured me several times that she would help me get my windows pc clean of spy and malware and first of all had me go to c:\windows\inf folder (this folder contains driver information). She told me that if there was more than 10 folders I was infected with spy and malware –  I played along and asked how we could get rid of this…

She assured me again that she could help me and went on at had me open the eventlog where i should be looking for errors and warning. All the reds (Errors) where Malware and all the Yellow (Warnings) where Spyware she told… come on – but ok, a lot of people might believe this. i sounded amazed and keep asking how we could get rid of this.

So now we finally got to something interesting where they would help me removed all this Spyware and Malware.

I should simply go to where you get redirected to LogMeIn 123  -Remote Support









By that time i pretty much knew where this were going and asked her if she really believed I was going to let her access my computer remotely. For the first time since I picked up the phone she didn’t say much for at least 4 seconds and by then se told me that she would get her support supervisor so that he could help me. So then I spoke to another dude asking me if I could enter my 6-digit code… I told him I didn’t have any 6-digit code and even if I did I was perfectly aware of what LogMeIn is used for and I has no intention of letting anyone who has called me up and telling me that they has information on my system running slow due to Malware and Spyware, access my computer and that he must be crazy to think that I would.

He hung up…

So let this be a reminder for those of you to recieve unwanted calls for these guys.

If you haven’t contacted some kind of support, there is no reason to beleive that stranger calling you should have any information on how your computer is running.
You should never let someone you don’t know access your system by any means – LogMeIn, TeamViewer etc.

Have i nice day




Leave a comment

Working with Reporting Services in SharePoint 2010

As you probably knows SharePoint 2010 can be used to show off SQL server Reporting Services (SSRS) reports. By registering a SQL server running Reporting Services in SharePoint Native mode you can deploy reports to a sharepoint Document library and have either the ReportViewer applicationpage og the Report Viewer webpart show to report directly in your browser.

Both the Report viewer applicationpage and the webpart gets available when activating the Sitecollection feature “Report Server Integration Feature”

By default when clicking a deployed (or manually uploaded) report (*.rdl file) SharePoint will let you view it in the Report viewer page (_layouts/ReportServer/RSViewerPage.aspx)

The report viewer page takes the URL for the report as a parameter like so:


You can furthermore add different parameters to the querystring to handle Report input parameters and different settings to control how the report is shown and rendered. More on that later

The Report viewer webpart can either takes the url for the deployed report or you can connect the webpart to a list view webpart that show the reports in a documentlibrary and thereby having the report viewer webpart show the report you select ind the List View webpart.

Setting up reporting Services
There are a lot of guides showing how to set up Reporting Services in ShaerPoint so I’ll only add some links here.

Building reports
When building reports for Reporting Services you should use Business Intelligence Development Studio (also known as BIDS) BIDS is part of the Visual Studio 2008 package and can be installed when installing the SQL Server 2008. Why not Visual Studio 2010 you think! Because there are no SQL Server 2010…

Building report are fairly easy and you don’t even have to known very much SQL to make it work. However when creating advanced reports you’ll most likely have to know some T-SQL to make your way.

The next few steps show you how to build a Report that shows all the products from the Northwind sample database. Can be downloaded here

  1. Open BIDS
  2. Create New project
  3. Select Report Server projet template (Fill in name etc.)

4.  Your Solution explorer should look like this

5. Right click Shared datasource and select “Add New Data Source”
6. Give it a name “Northwind datasource” and select Edit
7. Fill in servername, credentials, select database and test connection, press ok

8. We now have our datasource setup – Click ok
9. In Solution explorer right click Reports and select Add New Report

10. Verify that you have selected the newly created datasource “Northwind datasource” and click Next
11. Click Query builder OR type in your TSQL
12. In the Query Designer hit the “Add table” icon and select table: Products

13. Check columns: ProductID, ProductName, UnitPrice, UnitsInStock and click ok to close the Query Designer and then Next
14. Select the Tabular report type and click next

15. add all columns to details section and click Next
16. Select the Cooperate style and click Next
17. Name the report “Northwind products” and click Finish

18. You have now created your first report
19. You can easily pull or push the columns to make to report look nicer
20. And then try to preview

But that isn’t much fun unless you publish it to a Sharepoint Site so lets move on

Deploy the Report to a SharePoint site
The deployment of your report from BIDS its pretty easy but if you just right click your project and hits Deploy you’ll almost certainly fail

First of all you have to create a site to host your report

1. Create a plain teamsite

2. Create a document library for your Reports

3. Create a document library for your Shared Data Sources

4. Now you need to do some configuring in your BIDS to make the Deployment work. Right click your project in Solution explorer and click Properties.
5. Fill in

– TargetDataSourcefolder: http://sharepoint/ReportingServices/SharedDataSources
– TargetReportFolder: http://sharepoint/ReportingServices/Reports
– TargetServerUrl: http://sharepoint/ReportingServices

The Properties page should look like this

6. Click ok
7. Right click your project in Solution Explorer and select Deploy

Your output should look like this

8. Check your SharePoint site and validate that your shared data source and your report are deployed
9. The datasource is deployed

10. And the report is deployed

11. Now click the “Northwind products” report and lets see it work

Url for the Report is: http://sharepoint/ReportingServices/_layouts/ReportServer/RSViewerPage.aspx?rv:RelativeReportUrl=/ReportingServices/Reports/Northwind%20products.rdl

Passing parameters to the report
When loading the report we can pass different parameters in the querystring

More on that here:
and here:

Leave a comment

SharePoint Powershell codesamples

Here are some powershell codesamples that I use frequently and got tired of finding the code everytime:

Task: Looping All sites and webs in a webapplication:

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$htmlPrefix = "http://" # or use https:// for SSL sites
#$appHostNames = @("", "", "")
foreach($appHostName in $appHostNames)
  $siteUrl = $htmlPrefix + $appHostName
  Write-Host "Do something with all sites under this webapp: " $siteUrl
  $rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
  $spWebApp = $rootSite.WebApplication
  foreach($site in $spWebApp.Sites)
    Write-Host "You can now do something with this SPSite object : " $site.RootWeb.Url
    foreach($web in $site.AllWebs)
      Write-Host "You can now do something with this SPWeb object : " $web.Title "("$web.Url")"
      # Or if you need to access Publishing web object
      $pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)

Task: Setting New page default pagelayout
This example set the Publishings webs default pagelayout to “MyCustomPageLayouts.aspx” which is located in the gallary. The way to do this by the UI is Site Settings > Page layouts and site templates (Look and Feel section) > New Page Default Settings (section)  (/_Layouts/AreaTemplateSettings.aspx)

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$site = Get-SPSite ""
$web = $site.RootWeb
$pweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$layout = $pweb.GetAvailablePageLayouts() | ? {$_.Name -eq "MyCustomPageLayout.aspx"}
$pweb.SetDefaultPageLayout($layout, $false)

Task: Adding specific Mime Type to Specific Webapplication
This example (found at Mathieus blog) shows how you can add a specific MimeType to the Allowed Mimetypes for a WebApplication. This example adds the PDF mime type. A large list of Mime types can be found here

Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
#Mime Type Examples: "application/pdf, text/html, text/xml, application/x-shockwave-flash"
$mimetype = "application/pdf"
$webapp = Get-SPWebApplication ""
If ($webapp.AllowedInlineDownloadedMimeTypes -notcontains $mimetype)
  Write-Host "Adding MIME Type..."    
  Write-Host "Done."
  Write-Host -ForegroundColor Green "MIME type is already added."

By this way you can add specific allowed mimetypes without having to switch Browser File Handling from Strict to Permissive, which is normally done in Central administration > Manage Webapplications > Mark a Webapplication and select ‘General Settings’ in the Ribbon. With this option set to Permissive, all Mimetypes are allowed.

Browser File Handling settings

Task: Update list item
This example show how to update a listitem. In this case a DateTime field.

$SPSite = new-object Microsoft.SharePoint.SPSite("http://server/sites/sc")
$SPWeb = $SPSite.RootWeb
$SPList = $SPWeb.Lists["YourList"]
$SPItem = $SPList.GetItemById("4")
$SPItem["Some date"] = "01/01/2011 00:00:00"

Task: Get a list of all WebTemplates with information

This example show how to get a complete list of all web templates that can be used to create sites, including templates saved by users to the site collections template gallary.

Get-SPWeb http://YourSiteUrl | %{$_.GetAvailableWebTemplates($_.Language)} | Format-List

This post will be updated as time goes by and I run into SharePoint Powershell issues…

1 Comment