1

I'm trying to build a fully functioning powershell script that will merge user accounts, loop through all the site collections and delete the 2 user accounts, then execute audience compilation. I've got parts 1 and 2 working after a bit of work, but I'm hung up on hooking into audiences. I've seen this post by Per, and it always bombs out on line 3 with:

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

If I do a $context, it gives me a GUID of all zeroes. I'm developing this on my local windows 7 machine, full admin access to everything.

$site = Get-SPSite "http://localhost" 
$context = Get-SPServiceContext $site; 
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context); 
$audmgr = New-Object Microsoft.Office.Server.Audience.AudienceManager($context)
$aud = $audmgr.GetAudience("Irvine")
1

Bleh, I wasn't listed in the permissions of the service application even though I was listed as an administrator.

enter image description here

Image and fix courtesy of get-spscripts

0

Someone over on the MSDN forums had the same issue. They fixed it by changing the way the context was instantiated. Basically do this:

[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
$context = [Microsoft.Office.Server.ServerContext]::GetContext($mysite)
$upm =  New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

Source: http://social.technet.microsoft.com/Forums/sharepoint/en-US/7acf5c34-798b-4cee-a219-96d1ba4832c9/create-user-profile-manager-class-instance-using-powershell?forum=sharepointgeneralprevious

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.