Skip to content

Instantly share code, notes, and snippets.

@aflyen
Last active February 8, 2018 12:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aflyen/10836851 to your computer and use it in GitHub Desktop.
Save aflyen/10836851 to your computer and use it in GitHub Desktop.
Auto-Follow Sites in SharePoint 2013
# Get UserProfile Manager
$site = Get-SPSite -Limit 1
$serviceContext = Get-SPServiceContext($site)
$profileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)
$profiles = $profileManager.GetEnumerator()
# Iterates through all the user profiles
foreach ($profile in $profiles)
{
$followingManager = New-Object Microsoft.Office.Server.Social.SPSocialFollowingManager($profile)
# Create a new social actor object for the site to follow
$socialActor = New-Object Microsoft.Office.Server.Social.SPSocialActorInfo
$socialActor.ContentUri = "http://intranet/sites/important-news-from-corp" # REPLACE THIS WITH YOUR SITE
$socialActor.ActorType = [Microsoft.Office.Server.Social.SPSocialActorType]::Site
# Follow the mandatory site
if (!$followingManager.IsFollowed($socialActor))
{
$followingManager.Follow($socialActor)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment