This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Enable-CustomLikesRatingsOnLibrary { | |
[CmdletBinding()] | |
Param( | |
[Parameter(Mandatory=$true)] | |
[Microsoft.SharePoint.Client.Web]$Web, | |
[Parameter(Mandatory=$true)] | |
[String]$ListRelativeUrl | |
) | |
# Get required fields | |
$AverageRatingField = $Web.Fields.GetById([guid]"5a14d1ab-1513-48c7-97b3-657a5ba6c742") # AverageRating | |
$RatingCountField = $Web.Fields.GetById([guid]"b1996002-9167-45e5-a4df-b2c41c6723c7") # RatingCount | |
$RatedByField = $Web.Fields.GetById([guid]"4D64B067-08C3-43DC-A87B-8B8E01673313") # RatedBy | |
$RatingsField = $Web.Fields.GetById([guid]"434F51FB-FFD2-4A0E-A03B-CA3131AC67BA") # Ratings | |
$LikesCountField = $Web.Fields.GetById([guid]"6E4D832B-F610-41a8-B3E0-239608EFDA41") # LikesCount | |
$LikedByField = $Web.Fields.GetById([guid]"2CDCD5EB-846D-4f4d-9AAF-73E8E73C7312") # LikedBy | |
$Context.Load($AverageRatingField) | |
$Context.Load($RatingCountField) | |
$Context.Load($RatedByField) | |
$Context.Load($RatingsField) | |
$Context.Load($LikesCountField) | |
$Context.Load($LikedByField) | |
Execute-SPOQuery | |
# Get the library for the site | |
$ServerRelativeUrl = $Web.ServerRelativeUrl | |
if ($ServerRelativeUrl -ne "/") | |
{ | |
$ServerRelativeUrl = $ServerRelativeUrl + "/" | |
} | |
$List = $Web.GetList($ServerRelativeUrl + $ListRelativeUrl) | |
$ListRootFolder = $List.RootFolder | |
$ListRootFolderProperties = $ListRootFolder.Properties | |
$Context.Load($List) | |
$Context.Load($ListRootFolder) | |
$Context.Load($ListRootFolderProperties) | |
Execute-SPOQuery | |
# Add fields | |
$List.Fields.Add($AverageRatingField) | |
$List.Fields.Add($RatingCountField) | |
$List.Fields.Add($RatedByField) | |
$List.Fields.Add($RatingsField) | |
$List.Fields.Add($LikesCountField) | |
$List.Fields.Add($LikedByField) | |
$List.Update() | |
Execute-SPOQuery | |
# Update default view | |
$ListDefaltView = $List.DefaultView | |
$Context.Load($ListDefaltView) | |
Execute-SPOQuery | |
$ListDefaltView.ViewFields.Add("LikesCount") | |
$ListDefaltView.Update() | |
Execute-SPOQuery | |
# Update property bag | |
$ListRootFolderProperties["Ratings_VotingExperience"] = "Likes" | |
$ListRootFolder.Update() | |
Execute-SPOQuery | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment