I found this script at MSDN forum
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
$web = Get-SPWeb https://www.contoso.com/teams/yourteam
$context = [Microsoft.SharePoint.SPServiceContext]::GetContext([Microsoft.SharePoint.SPSite]$web.Site)
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager $context
$users = $web.AssociatedMemberGroup.Users | where IsDomainGroup -eq $false
$useraccounts = $users | select loginname | Foreach {"$($_.loginname)"}
foreach ($user in $users) {
$profile = $upm.GetUserProfile($user.UserLogin)
#$objectToFollowRelativeToWeb = "/"
if ($profile)
{
#Create a Social Manager profile
#SPSocialFollowingManager
$followManager = New-Object Microsoft.Office.Server.Social.SPSocialFollowingManager($profile, $context)
$following = $followManager.GetFollowed([Microsoft.Office.Server.Social.SPSocialActorTypes]::Users)
for ($i=$following.Count - 1; $i -ge 0; $i--) {
$followed = $following[$i]
$acctname = $followed.AccountName
#if claims:
$acctname = 'i:0#.w|'+$acctname
if ($acctname -iin $useraccounts ) {
[Microsoft.Office.Server.Social.SPSocialFollowResult]$res = $followManager.StopFollowing($followed)
Write-Verbose "$($user.UserLogin) stop following $acctname result is $res"
}
}
}
}
I believe the logic is correct and all the module being called seems correct. However after I run above script on my fine nothing have changed. The users are still following the same users.
After some investigation, under PeopleManager there is also StopFollowing method. (the script above is calling SocialFollowingManager.StopFollowing) Do you think this two "Stopfollowing" are running differently? How could I fix above script?