Introduction
The following script will help make everyone in the user profile follow a single user. We sometimes receive requests from clients where they want a certain account to be followed by everyone. In that case, the below script will be very helpful.
- Add-PSSnapin microsoft.sharepoint.powershell -EA SilentlyContinue
-
- $site = Get-SPSite "any site collection url"
-
- $serviceContext = Get-SPServiceContext($site)
-
- # Represents a collection of UserProfile objects that are used to access user profile data.
-
- $profileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)
-
- $profiles = $profileManager.GetEnumerator()
-
- foreach ($profile in $profiles)
- {
-
- Write-Host $Profile.AccountName "|" $Profile.DisplayName;
-
- #Initializes a new SPSocialFollowingManager instance for the specified user and service context.
-
- $followingManager = New-Object Microsoft.Office.Server.Social.SPSocialFollowingManager($profile, $serviceContext)
-
-
- # Create a new social actor object for the User to follow
-
- $socialActor = New-Object Microsoft.Office.Server.Social.SPSocialActorInfo
-
- $socialActor.AccountName = "Domain\username" # Provide the user account details which should be followed by everyone
-
- $socialActor.ActorType = [Microsoft.Office.Server.Social.SPSocialActorType]:: User
-
- $followingManager.Follow($socialActor)
-
-
- }
Once the script is run, you can verify for any user in the user profile by navigating to the MySite of the user. The URL for any user's MySite would look like https://mysite web app/personal(managed path set while creating user profile)/ID of the User -> NewsFeed -> Click on the number of the user you are following (19 in below screenshot) and you can see the user in the page you are redirected to.
Thank you! Please post your queries in case of any issue,
Saurav