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

SiteSubscriptionId
------------------
00000000-0000-0000-0000-000000000000

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


Ingen kommentarer:

Send en kommentar