torsdag den 28. februar 2013

Error on UserProfileManager and a funny SiteSubscriptionId

So I was struggling a little bit with an old PowerShell script to import pictures to the user profiles on our Intranet. The script was not working and I need to figure out what went wrong.
So the script is well documented on various forums, so that should be no big deal in getting this to work. So I went head first, and in to the pool I went.

So the script looks like this.
$site = Get-SPSite $mySiteUrl
$context = Get-SPServiceContext $site
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

So the first part was easy, just getting the “mysite” URL, Next part to get the mysite service context. Now again quit easy. But then I had to get the profile manager. Then some problems came up.
So when trying to get the profile manager I got this error when running the commands manual.

New-Object : Exception calling ".ctor" with "1" argument(s): "Object reference not set to an instance of an object.” At line:1 char:29
+ $profileManager = New-Object <<<< Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

So this had to be the problem to my script.
After some quick test I found my context hade a funny SiteSubscriptionId


So I found that the SiteSubscriptionId will always be a blank Guid unless you have multi-tenancy enabled in the environment, so the problem should be found elsewhere.
I my case I found out that the user running the script was net in the administrators group of the service provider, so adding the user running the script to the group fixed the problem.

Go to Central Administration => Application Management => Manage Service Applications 
Highlight the row “User Profile Service Application”

Click the administrators in the ribbon and add the correct user.
Click the Permissions in the ribbon and add the correct user

onsdag den 27. februar 2013

Speech at jBoye

Today I hold a speech at the one of jBoye network seminar's, on the topic (High availability with SharePoint 2013). A fun presentation as this was my first try on using the Microsoft metro style.

For the ones that know Danish will be able to read the slides. but your all welcome to leave a comment.
(Please mind that all Saxo Bank specific slides have been removed)


onsdag den 20. februar 2013

Adding SharePoint PowerShell snapins

Over time I have seen a lot of ways to add the SharePoint snapins. So I decided that I would share my point of view on this.

So a lot of post on the internet is showing various ways to do this, by as the structure fascist I am, I like to keep things organized. So I always put my code in functions.


Well first it gives you a nice overview of the code, Always put your main code in a main function. This way it’s always on the top of your script. Second. By adding all your code in functions you can call the reuse then over and over again in your script.

It’s also a good idea to let your script tell you where in the process it is. This gives you a nice overview over watt you script is doing

So how do I add the snapin.

function snapin
  $spSnapin = Get-PSSnapin | where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}        
  if($spSnapin -eq $null)
    Add-PSSnapin Microsoft.SharePoint.PowerShell
    Write-Host -ForegroundColor "Green" -Object "SharePoint PowerShell Snapin loaded"
     Write-Host -ForegroundColor "Gray" -Object "SharePoint PowerShell Snapin already loaded"
So after adding this function I call this function just before I call the main function. My structure will always look like this.

function snapin

# end of script

onsdag den 13. februar 2013

Adding December 2012 CU to the Codeplex AutoSPInstaller

After struggling with the slipstreaming problem that Microsoft has introduced after June 2012 CU. I decided to embed this update function to the script itself. This also gives the flexibility to add future updates to the script without using the slipstream functionality.

The function is quit strait forward, just add the unattended install line to a function and call this function after the language pack install. You need to make a folder called "Hotfixes" inside the SharePoint bits folder, and place the update there.

For more information on the AutoSPInstaller from codeplex follow this link.   

Here is the function to add

#region Install CU updates
# ===================================================================================
# Func: Install SharePoint CU's
# Desc: Installs the SharePoint collumutive update in unattended mode
# ===================================================================================
function InstallCu()
  if(!(test-path -path $SPbits\Hotfixes)){Write-Host "You do not have an hotfix folder"; return}
  $Media = Get-ChildItem $SPbits\Hotfixes | where {$_.Extension -eq ".exe"} | sort-object $_.Name
  if($Media -eq $null){write-host "There is now (Cu).exe files in the Hotfix folder"; return }
    foreach($InstallationFile in $Media)
       Write-Host "Installing:" $InstallationFile.Name
       $InstallStart = Get-Date
         . $SPbits\Hotfixes\$InstallationFile /passive /log:$CurrentPath\Logs\$InstallationFile.Name.txt | out-null
         Throw "- Installation of CU failed"
  Write-host " The installation of CU completed"

More info on using the slipstreaming read this post made by Todd.

fredag den 8. februar 2013


I went to the conference for some inspiration and to hear a lot of great community MVP’s talk about all the new stuff in SharePoint 2013.

I will post some more comments and lessons learned later.