Share Point Activity feed power shell script error
-
08-12-2019 - |
Domanda
#Add SharePoint PowerShell SnapIn if not already added
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
[void] [System.Reflection.Assembly]::LoadWithPartialName("System")
$site = Get-SPSite "http://mysite/"
$context = Get-SPServiceContext $site;
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context);
$profile1 = $upm.GetEnumerator()
while($profile1.MoveNext())
{
$am = New-Object Microsoft.Office.Server.ActivityFeed.ActivityManager($myprofile1, $context)
$type = $am.GetType()
$methodInfo = $type.GetMethod("CopyBasicUserInfo", [reflection.bindingflags]"nonpublic,instance", $null, $profile1.GetType(), $null)
$methodInfo.Invoke($am,$profile1.Current)
$apptList = New-Object System.Collections.Generic.List[Microsoft.Office.Server.ActivityFeed.ActivityPreferencePerType]
$am.ActivityApplications["UserProfileChange_Gatherer"].ActivityTypes | ForEach-Object {
$appt = New-Object Microsoft.Office.Server.ActivityFeed.ActivityPreferencePerType
$appt.ActivityType = $_
$Username = $profile1.Current.DisplayName
if($_.ActivityTypeName -eq "Birthday_Reminder") {
$appt.IsSet = $false
write-host "Updating Activity Feed Property Birthday_Reminder for " $Username
}
else{
$appt.IsSet = $true
}
$apptList.Add($appt)
} # For Each Object Ending
$am.ActivityPreferences.SetActivityPreferencesPerType($apptList)
$am.ActivityPreferences.Commit()
$am.ActivityPreferences.Refresh()
} # While Userprofile Ending`enter code here`
Soluzione
Replace the foreach on userprofiles with this while($profile1.MoveNext())
and $profile1.Current
will return you the current user profile. Sample
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$iterator = $upm.GetEnumerator()
while($iterator.MoveNext())
{
Write-Host $iterator.Current.DisplayName
}
Altri suggerimenti
You are piping ActivifyTypes into an foreach which you're also using to loop through $AllProfiles you need two foreach instead of one
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange