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! 🙂
# 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) } }
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.
Your post was very helpful, however i have a different problem:
I need to make all users on the site to follow a set of users using powershell. Is it possible?
As of now i have seen articles making users follow specific site or making current user to follow others. Is there a way to make by default every user on the site to follow a set of users
You should look into the lines where the type of the sosial actor is set. Change the type of SPSocialActorType to User and set the value in a proper manner and I guess it would work.
Can we achieve it in SharePoint Online with CSOM PowerShell?
I haven’t tried it myself, but from the documentation on MSDN (https://msdn.microsoft.com/en-us/library/office/jj163130.aspx) it looks like it should be possible through CSOM or REST.
Will this work in Sharepoint in Office 365?
Nice script! Thanks for sharing!
I am facing this problem:
Exception calling “Follow” with “1” argument(s): “The operation failed because an internal error occurred. Internal
type name: Microsoft.Office.Server.UserProfiles.FollowedContentException. Internal error code: 11.”
At C:\Scripts\MakeUserFollowSharePointSite.ps1:20 char:9
+ $followingManager.Follow($socialActor)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SPSocialException
Has anyone been experiencing the same error with this script?
Help would be appreciated. Thanks a lot.
Some have mentioned that it can occur when using a CU between september 2015 and february 2016. Which CU do you have?
Hey Are Flyen, we are on version 15.0.4841.1000 (CU July 2016). Have tried to modify the script in may ways. Still no success.
If it is “version-related” then we may have no chance. Thanks for your effort and answer.
Ok – bit of a newbie here but, love the idea of the script, the only modification that needs to be made to run it appears to be adding the site in the line – $socialActor.ContentUri = “http://intranet/sites/important-news-from-corp” # REPLACE THIS WITH YOUR SITE. Is that correct? Thank you so much for putting this up here!
Thanks for this nice post. I wonder if it is possible to run the script only for user within a certain security group in Office365 and if it is also possible to run two scripts, meaning one script for each of the two groups (with different sharepoint sites to follow). Any help would be highly appreciated!