Skip to main content

SharePoint 2010 Compile All Audiences

This was a pain figuring out so many posts were wrong. Thanks to Jasper ( for the corrections needed to get this working. I am very close to having my FIM 2010 implementation call the SharePoint 2010 FIM run profiles and then compile all the audiences on a more than once a day schedule.

Update 2011-11-17: Small change, I couldn't get the compile all call to work, so I resorted to compiling each individually.
  1. Add-PSSnapin Microsoft.SharePoint.PowerShell  
  3. $AUDIENCEJOB_START       = '1'  
  6. $site          = Get-SPSite ''  
  7. $context       = Get-SPServiceContext $site  
  8. $proxy         = $context.GetDefaultProxy([Microsoft.Office.Server.Audience.AudienceJob].Assembly.GetType('Microsoft.Office.Server.Administration.UserProfileApplicationProxy'))  
  9. $applicationId = $proxy.GetType().GetProperty('UserProfileApplication', [System.Reflection.BindingFlags]'NonPublic, Instance').GetValue($proxy$null).Id.Guid  
  10. $auManager     = New-Object Microsoft.Office.Server.Audience.AudienceManager $context  
  12. $auManager.Audiences | Sort-Object AudienceName | Select-Object @{Name='Audience';Expression={$_.AudienceName}},@{Name='ReturnValue';Expression={[Microsoft.Office.Server.Audience.AudienceJob]::RunAudienceJob(@($applicationId$AUDIENCEJOB_START$AUDIENCEJOB_INCREMENTAL$_.AudienceName))}} | ft -auto  


  1. I use in the non-SharePoint sync world to perform FIM 2010 run profiles on demand, based on detected changes in the source systems (HR, AD, etc.). This tool can run the FIM sync service for SharePoint using the same paradigm, and fire your powershell script after every legitimate update to SharePoint. I am just working on setting exactly this scenario in a lab. Interested?


Post a Comment

Popular posts from this blog

PowerShell SupportsShouldProcess Worst & Best Practices

This has been a very big discussion within the Scripting Games 2013 community and I want to add my two cents in an official blog post.

I've left several people comments on how they might be misunderstanding how SupportsShouldProcess works, but I also realize, everyone of these individuals has given me more insight into its use and perhaps, how it should best be utilized.

For those of you that don't know, SupportsShouldProcess is a parameter on the CmdletBinding attribute you can place on your cmdlets that automatically adds the -WhatIf and -Confirm parameters. These will naturally flow into other cmdlets you use that also SupportsShouldProcess, e.g. New-Item, Move-Item.

The major discussion has been around, should you just let the other cmdlets handle the $PSCmdlet.ShouldProcess feature, and if not how should you implement it. ShouldProcess has the following definitions.

FIM 2010 R2 Self-Service Password Reset Auto-Registration

I have been working on our FIM 2010 R2 SP1 lab environment looking for ways to simplify some of the overly complicated scenarios we had to implement to workaround the limitations in FIM 2010. One of those workarounds was the auto-registration of SSPR for new employees. When we onboard a new employee, we want to create a simple SSPR for them to get their first-time password reset.

Prior to the R2 release we were using the client and PowerShell to complete the registration process on a daily schedule. I was working on converting this to use the R2 registration cmdlets and combined it with PowerShell 3.0 Workflows to get to a solution similar to this.
[CmdletBinding()]  param()  begin {      workflow Invoke-RegisterSSPR {          InlineScript {              Import-Module FIM          }  $workflow = InlineScript { Get-FIMResource -Filter '/WorkflowDefinition[DisplayName = "Password Reset AuthN Workflow for New Employees"]' }  $members  …

PowerShell Error Handling Behavior Debunked

Note: I am using simple error messages as an example, please reference the best practices and guidelines I outlined on when to use custom error messages.

I have been churning in my mind for the last few days all the entries in the 2013 Scripting Games and how they handle errors, or lack thereof.

I am coming to the conclusion through some testing that the simple fact of seeing a try..catch or throw statements does not mean there is proper error handling.

I've been testing several variations and forms of error handling, so lets start with the basics.
function Test-WriteError {      [CmdletBinding()] param()  "Test-WriteError::ErrorActionPreference = $ErrorActionPreference"Move-Item -Path 'C:\Does\Not\Exists.log' -Destination 'C:\No\Where'"Test-WriteError::End"}   Test-WriteError::ErrorActionPreference = Continue
Move-Item : Cannot find path 'C:\Does\Not\Exists.log' because it does not exist.
At line:6 char:5
+     Move-Item -Path 'C:\Does\N…