Following sites using PowerShell and the Social API in SharePoint 2013
In SharePoint 2013 you can now as a end-user choose to follow sites to both subscribe to their newsfeed, but also to maintain a list of favorites under "Sites" in your MySite. From the administrator point of view, there are no features to push these sites to your users, but with the API's available, this doesn't require much effort to achieve.
Case
A user story described that one site in the solution was mandatory to follow since all important company news should be published here. It wasn't good enough to trust that end-users chose to follow this site, so a solution to enforce this policy was needed. This is an excellent way to turn some of the traditional news articles to a modern social news item, and showing the users that the company itself also adopts the social strategy.
Solution
For this I created a PowerShell script that is scheduled to run each night. The script iterates through all the User Profiles in MySites, and checks if the user subscribes to the mandatory site, and if they don't the site will be followed for them. If you try to be smart an unfollow the site, wait until midnight and you are back in! :-)
[code language="powershell"]
# 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)
}
}
[/code]
Summary
Using PowerShell and the SharePoint Social API enables us to create solutions that implements business policies like this one requiring us to follow a spesific site. As an example this can be extended in other purposes like helping users to follow their organization site.
Disclaimer: The script presented here is not intended for production purpose, and should only be treated as an example.