Category: SharePoint 2010

Audience Compilation Status is ‘Compiling’ for a long time

Looking at Central Administration console under Manage Profile Service we have noticed that Audience Compilation Status shows ‘Compiling’ for a long time. There is no errors in the event logs. Attempts to stop compilation or compile an individual audience did not produce any results.

There is AudienceJob.exe executable that you can use to manipulate audiences:

AudienceJob.exe <Application Id> [Crawl Type] [Audience Name]
Application Id: Guid corresponding to UserProfile application
Command: 1 = Start, 0 = Stop
Crawl Type: 1 = Full, 0 = Incremental (default = 1)
Audience Name: Specific audience to compile (default = all)

####################################################################################################
#
#  Author.......: David Shvartsman
#  Date.........: 05/18/2018
#  Description..: Restart Audience Compilation
#
#################################################################################################### 
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$ServiceType = "User Profile Service Application"
$spService = Get-SPServiceApplication  | where {$_.TypeName -like $ServiceType }
$id = $spService.id
Audiencejob.exe $id 0 
Audiencejob.exe $id 1

You can use AudienceJob.exe to compile a specific audience.

It works in SharePoint 2010, SharePoint 2013 and SharePoint 2016.

That was another page in the Chronicles of SharePoint Bits, happy scripting!

Use PowerShell to compile SharePoint 2010 and 2013 Audiences list

Audiences is a feature of User Profile Service Application that allows list or document library items in SharePoint to be targeted to appear only to people who are members of a particular group or audience. An audience can be identified by using SharePoint groups, distribution lists, or security groups or by using a rules-based system based on User Profile Properties.

For more information see the Target content to specific audiences article.

You can change the Audience Compilation Schedule using Central Administration under: Application Management/Manage Service Applications/User Profile Application/People/Schedule Audience Compilation or use PowerShell (tested in SharePoint 2010 and 2013). The PowerShell will also come in handy when you have Compilation Job stock in progress.

The script bellow will find User Profile Properties ID and stop and restart Audiences Compilation Job.

 
#####################################################################################################
# Author.......: David Shvartsman 
# Date.........: 3/13/2017 
# Description..: Use PowerShell to compile SharePoint 2010 and 2013 audience list 
##################################################################################################### 

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
$runjob=[Microsoft.Office.Server.Audience.AudienceJob]::RunAudienceJob($args);
#Get User Profile Service Application Id
$appUPA = Get-SPServiceApplication | Where {$_.TypeName -eq 'User Profile Service Application'}
if ($appUPA) {
    #Stop Audiences Compilation Job
    Audiencejob.exe $appUPA.Id 0
    #Start Audiences Compilation Job
    Audiencejob.exe $appUPA.Id 1
}

That was another page in the Chronicles of SharePoint Bits, happy scripting!

SharePoint – Problem with user changing it’s Name

Each time user interacts with SharePoint Content (Edits/Adds/Deletes) on the particular Site, SharePoint stores some user metadata (Email, DisplayName, LoginName, etc) in the ‘User Information List’ (hidden system list). That allows SharePoint to minimize the load on User Profile Application. That information is used to populate current user name (upper right corner in SharePoint 2013), Document Creator Name, Document Last Update by Name, etc.

In case when user interacted with the particular site before the name change, the old name would have been stored in the ‘User Information List’ and will be used from that point forward to populate document properties, User Info, etc.

Unfortunately, Removing the user from ‘User Information List’ of that particular site will remove that user permission on that site. You can use Set-SPUser command to update Display Name Property:

####################################################################################################
#
#  Author.......: David Shvartsman
#  Date.........: 06/28/2016
#  Description..: Updates Users Name in the 'User Information List'
#
####################################################################################################
if ((Get-PSSnapin 'Microsoft.SharePoint.PowerShell' -ErrorAction SilentlyContinue) -eq $null) {
  Add-PSSnapin 'Microsoft.SharePoint.PowerShell'
}
 
cls
#Remove the Kerberos token prefix i:0#.w| if Kerberos Authentication is not being used
$userId = 'i:0#.w|<Domain>\<UserId>'
$UserDisplayName = '<User Full Name>'
 
CLS
$spAssignment = Start-SPAssignment
# Get All Web Applications
$WebApps=Get-SPWebApplication 
foreach($webApp in $WebApps) {
    foreach ($spSite in $webApp.Sites) {
        foreach($spWeb in $SPsite.AllWebs) {
            try {
                $user = $spWeb | Get-SPUser -Identity $userId -ErrorAction stop
                if ($user.DisplayName -ne $UserDisplayName) {
                    Write-Host "Updating Name $($user.DisplayName) in $($spWeb.Url)"
                    Set-SPUser  -Identity $userId  -web $spWeb.url -DisplayName $UserDisplayName -Confirm:$false
                }
            }
            catch {}
        }
    }
}
Stop-SPAssignment $spAssignment

To see the value of the User Information List Properties you can use the following code:

CLS
#Remove the Kerberos token prefix i:0#.w| if Kerberos Authentication is not being used
$userId = 'i:0#.w|domainName\userId'
$spWeb = Get-SPWeb -Identity 'Site URL'
$user = $spWeb.EnsureUser($userID)
$item = $spWeb.SiteUserInfoList.Items.GetItemById($user.ID)
foreach ($field in $item.fields) {
    Write-host 'Title: $($field.Title) ($($field.InternalName)) Value: $($item[$field.InternalName])'
}

Additional Information:

Set-SPUser
Get-SPUser

For more details on User Information se the TechNet post: https://gallery.technet.microsoft.com/User-Information-List-in-8b420e8c

The scripts work in SharePoint 2007, SharePoint 2010, SharePoint 2013, SharePoint 2016 and SharePoint Online Name>