Hi Readers,
We have got a requirement to remove group memebership newsfeed from all user profiles as users are getting annoyed.
We have researched alot & found no OOB way to turn this off globally but we have found a script on the internet that will uncheck the activities
in all userprofiles.
But as user have a way in mysite userprofile to check it again so we scheduled it to run daily so that it get unchecks automatically.
Create XML file as below for the attributes which you want to uncheck. If you only want to touch some attributes, don’t include others in xml file as otherwise those attributes will also get set as false or true.
In our case we have included only NewMembership attribute & set it as false. Also, i have modified the script to include the log on the basis of date.
########################## XML file : ConfigActivityFeed.xml ############################
<?xml version="1.0" encoding="utf-8" ?> <ActivityTypes> <URL>http://dev.mysite.com/</URL> <ActivityType Name="StatusMessage" IsSet="True"></ActivityType> <ActivityType Name="SocialTaggingByAnyone" IsSet="False"></ActivityType> <ActivityType Name="SocialRatings" IsSet="True"></ActivityType> <ActivityType Name="DLMembershipChange" IsSet="True"></ActivityType> <ActivityType Name="SharingInterest" IsSet="True"></ActivityType> <ActivityType Name="SocialTaggingByColleague" IsSet="True"></ActivityType> <ActivityType Name="NoteboardPosts" IsSet="True"></ActivityType> <ActivityType Name="TitleChange" IsSet="True"></ActivityType> <ActivityType Name="ManagerChange" IsSet="False"></ActivityType> <ActivityType Name="BlogUpdate" IsSet="True"></ActivityType> <ActivityType Name="WorkplaceAnniversary_Reminder" IsSet="False"></ActivityType> <ActivityType Name="WorkplaceAnniversary_Today" IsSet="False"></ActivityType> <ActivityType Name="ColleagueAddition" IsSet="True"></ActivityType> <ActivityType Name="ProfilePropertyChange" IsSet="True"></ActivityType> <ActivityType Name="Birthday_Reminder" IsSet="False"></ActivityType> <ActivityType Name="Birthday_Today" IsSet="False"></ActivityType> </ActivityTypes>
####################### ConfigActivityFeed.ps1 ###############################
#—————-Get the xml file—————————————————————
[xml]$xmlData=Get-Content “ConfigActivityFeed.xml”
#—————-Set Activity Feed Preferences————————————————–
function SetActivityFeed
{
Param(
[Microsoft.Office.Server.ActivityFeed.ActivityManager]$UserActivityManager,
[string]$User
)
#———————————————————————————————————
$date = get-date -format d
# replace \ by –
$date = $date.ToString().Replace(“/”, “-”)
$output = “ActivityTypeName” + $date + “_.log”
$output1 = “ActivityFeedErrLog” + $date + “_.log”
try
{
$apptList = New-Object System.Collections.Generic.List[Microsoft.Office.Server.ActivityFeed.ActivityPreferencePerType]
$appts = $UserActivityManager.ActivityPreferences.GetActivityPreferencesPerType()
$ats = $UserActivityManager.ActivityTypes
$User >> “.\$output”
foreach($appt in $appts)
{
$appt.ActivityType.ActivityTypeName >> “.\$output”
#———————————————————————————-
# IsSet -> indicating whether a user wants to see the ActivityType object stored
# in this ActivityPreferencePerType in a feed
#———————————————————————————-
$appt.IsSet >> “.\$output”
#———————————————-
# Change the value of IsSet to check/uncheck
#———————————————-
$xmlData.ActivityTypes.ActivityType | ForEach-Object{
$typeName = $_.Name
if($appt.ActivityType.ActivityTypeName.Equals($typeName))
{
$appt.IsSet = [System.Convert]::ToBoolean($_.IsSet)
#write-host -f red “Check ActivityType: ” $appt.ActivityType.ActivityTypeName}
}
}
$apptList.Add($appt)
}
### Display value of properties
<#
foreach($type in $ats)
{
write-host -f green “ActivityTypeNameLocStringName:” $type.ActivityTypeNameLocStringName
write-host -f blue “ActivityTypeNameLocStringResourceFile:” $type.ActivityTypeNameLocStringResourceFile
write-host “ApplicationId:” $type.ApplicationId
}
#>
}
catch
{
Get-Date >> “.\$output1”
$_.Exception.ToString() >> “.\$output1”
}
$line = “————————————–”
$line >> “.\$output”
### Sets the current user’s preferences for each ActivityType object managed by the ActivityManager
$UserActivityManager.ActivityPreferences.SetActivityPreferencesPerType($apptList)
$UserActivityManager.ActivityPreferences.Commit()
$UserActivityManager.ActivityPreferences.Refresh()
}
#—————-Get Activity Manager with specific user account——————————————
function ConfigActivityFeed()
{
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}
if ($snapin -eq $null)
{
Write-Host “`nLoading SharePoint Powershell Snapin`n”
Add-PSSnapin “Microsoft.SharePoint.Powershell”
}
Try
{
$site = Get-SPSite $xmlData.ActivityTypes.URL
$context = Get-SPServiceContext($site)
### Get User Profile
$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
[void][System.Reflection.Assembly]::LoadWithPartialName(“System”)
$user = $upm.GetUserProfile(“abcd\sakiv”)
### Iterate all the user profiles
[System.Collections.IEnumerator] $en = $upm.GetEnumerator()
while($en.MoveNext())
{
$user = [Microsoft.Office.Server.UserProfiles.UserProfile]($en.Current)
$str = [Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName
$userName = $user[$str].Value.ToString()
write-host -f blue $userName
### Get Activity Feed Manager
$am = New-Object Microsoft.Office.Server.ActivityFeed.ActivityManager($user, $context)
### Using reflection to set preference for user; otherwise, only get preference of account which is used to login server
$methodInfo = $am.GetType().GetMethod(“CopyBasicUserInfo”, [reflection.bindingflags]”nonpublic,instance”, $null, $user.GetType(), $null)
### Invokes the method represented by the current object instance, using the specified parameters
### Invoke(Object obj, Object[] parameters)
$methodInfo.Invoke($am, $user)
SetActivityFeed -UserActivityManager $am -User $userName
}
}
Catch
{
write-error $_.Exception
Get-Date >> “.\$output1”
$_.Exception.ToString() >> “.\$output1”
}
write-host -f red “Done”
$site.Dispose()
}
#—– Call function —
ConfigActivityFeed
Start-Sleep -Seconds 50;
——————————————————————————————-
references :-
Regards
Sukhija Vikas