Skip to content
Are Flyen's Blog

Are Flyen's Blog

Office 365, SharePoint and Azure

  • About
  • Archive
  • Contact

Tag: User Profile

Posted on April 4, 2014

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! 🙂

# 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.

Are Flyen

Are Flyen is a developer and solution architect located in Norway. He works with SharePoint, Office 365 and Azure as a Chief Consultant at EVRY.

Recent Posts

  • Use the Full Page Canvas in modern SharePoint Online sites
  • Create a Communication Site from code in SharePoint Online using PowerShell
  • Problem with connecting to SharePoint Online in Office 365 with PowerShell, SharePoint Designer and other 3. party tools
  • “Create a team” is missing in Microsoft Teams
  • Create list from custom template in SharePoint with PowerShell

From Twitter

  • Blogged: Use the Full Page Canvas in modern SharePoint Online sites blog.areflyen.no/2018/04/05/use… #SharePoint #SPFx 2 years ago
  • Blogged: Create a Communication Site from code in #SharePoint Online using #PowerShell blog.areflyen.no/2017/07/16/cre… 3 years ago
  • Blogged: Problem with connecting to #SharePoint Online with #PowerShell (LegacyAuthProtocolsEnabled) blog.areflyen.no/2017/06/18/pro… 3 years ago
  • "You site collection is being created. It can take 15 minutes or longer to complete this task." #Performance #HopefullySoonHistory 4 years ago
  • Enable ratings with PowerShell and CSOM in #SharePoint: blog.areflyen.no/2016/09/11/ena… 4 years ago

Tags

  • Active Directory
  • API
  • Authentication
  • BCS
  • Collaboration
  • Development
  • Development environment
  • Error
  • Hyper-V
  • Integration
  • Intranet
  • ITPRO
  • Managed Metadata
  • Microsoft Teams
  • Migration
  • MySite
  • Navigation
  • Office 365
  • Office 365 Groups
  • OfficeDev PnP
  • PowerShell
  • Profile Pictures
  • Publishing
  • React
  • SharePoint 2010
  • SharePoint 2013
  • SharePoint 2016
  • SharePoint Framework
  • SharePoint Online
  • SkyDrive
  • Social
  • SPFx
  • Troubleshooting
  • TypeScript
  • Upgrade
  • User Profile
  • User Profiles
  • Web Parts
  • Windows 8
  • Windows Server 2012
  • Workflow
  • Yammer

Menu

  • About
  • Archive
  • Contact
Blog at WordPress.com.