From 795f4bec263b9f4bc176b11c70886f9d67eb7565 Mon Sep 17 00:00:00 2001 From: Nishkalank Date: Thu, 22 Feb 2024 19:50:38 +0100 Subject: [PATCH 1/2] New-Command-Get Page LikedBy Information --- .../Get-PnPPageLikedByInformation.md | 100 ++++++++++++++++++ src/Commands/Model/PageLikedByInformation.cs | 17 +++ .../Pages/GetPageLikedByInformation.cs | 52 +++++++++ 3 files changed, 169 insertions(+) create mode 100644 documentation/Get-PnPPageLikedByInformation.md create mode 100644 src/Commands/Model/PageLikedByInformation.cs create mode 100644 src/Commands/Pages/GetPageLikedByInformation.cs diff --git a/documentation/Get-PnPPageLikedByInformation.md b/documentation/Get-PnPPageLikedByInformation.md new file mode 100644 index 000000000..7a3b6e321 --- /dev/null +++ b/documentation/Get-PnPPageLikedByInformation.md @@ -0,0 +1,100 @@ +--- +Module Name: PnP.PowerShell +title: Get-PnPPageLikedByInformation +schema: 2.0.0 +applicable: SharePoint Online +external help file: PnP.PowerShell.dll-Help.xml +online version: https://pnp.github.io/powershell/cmdlets/Get-PnPPageLikedByInformation.html +--- + +# Get-PnPPageLikedByInformation + +## SYNOPSIS +Returns liked-by Information of a modern page + +## SYNTAX + +```powershell +Get-PnPPageLikedByInformation -Identity [-Connection ] +``` + +## DESCRIPTION +This command retrieves the LikedBy Information of a modern page. + + +## EXAMPLES + +### EXAMPLE 1 +```powershell +Get-PnPPageLikedByInformation -Identity "MyPage.aspx" +``` + +Gets the LikedBy Information of page named 'MyPage.aspx' in the current SharePoint site + +### EXAMPLE 2 +```powershell +Get-PnPPageLikedByInformation "MyPage" +``` + +Gets the LikedBy Information of page named 'MyPage.aspx' in the current SharePoint site + + +### EXAMPLE 3 +```powershell +Get-PnPPageLikedByInformation -Identity "MyPage.aspx" -Web (Get-PnPWeb -Identity "Subsite1") +``` + +Gets the LikedBy Information of page named 'MyPage.aspx' from the subsite named 'Subsite1' + +### Sample Output + +```powershell +Name : Johnny Bravo +Mail : +Id : 14 +LoginName : i:0#.f|membership|johnny.bravo@contosso.onmicrosoft.com +CreationDate : 2024-02-16 14:49:55 + +Name : Nishkalank Bezawada +Mail : SuperAdmin@contosso.onmicrosoft.com +Id : 6 +LoginName : i:0#.f|membership|superadmin@contosso.onmicrosoft.com +CreationDate : 2024-02-22 19:47:24 +``` + +## PARAMETERS + +### -Connection +Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. + +```yaml +Type: PnPConnection +Parameter Sets: (All) + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Identity +The name of the page + +```yaml +Type: PagePipeBind +Parameter Sets: (All) + +Required: True +Position: 0 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + + + +## RELATED LINKS + +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) + diff --git a/src/Commands/Model/PageLikedByInformation.cs b/src/Commands/Model/PageLikedByInformation.cs new file mode 100644 index 000000000..b9e522b30 --- /dev/null +++ b/src/Commands/Model/PageLikedByInformation.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PnP.PowerShell.Commands.Model +{ + public class PageLikedByInformation + { + public string Name { get; set; } + public string Mail { get; set; } + public int Id { get; set; } + public string LoginName { get; set; } + public DateTime CreationDate { get; set; } + } +} diff --git a/src/Commands/Pages/GetPageLikedByInformation.cs b/src/Commands/Pages/GetPageLikedByInformation.cs new file mode 100644 index 000000000..c966f5bb6 --- /dev/null +++ b/src/Commands/Pages/GetPageLikedByInformation.cs @@ -0,0 +1,52 @@ + +using PnP.Core.QueryModel; +using PnP.PowerShell.Commands.Base.PipeBinds; +using PnP.PowerShell.Commands.Model; +using System; +using System.Collections.Generic; +using System.Management.Automation; +using System.Text; + +namespace PnP.PowerShell.Commands.Pages +{ + [Cmdlet(VerbsCommon.Get, "PnPPageLikedByInformation")] + [OutputType(typeof(PageLikedByInformation))] + public class GetPageLikedByInformation : PnPWebCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0)] + public PagePipeBind Identity; + + protected override void ExecuteCmdlet() + { + var clientSidePage = Identity.GetPage(Connection); + + if (clientSidePage == null) + throw new Exception($"Page '{Identity?.Name}' does not exist"); + + var pageLikeInformation = clientSidePage.GetLikedByInformationAsync().GetAwaiter().GetResult(); + + var likes = pageLikeInformation.LikedBy.AsRequested(); + + var likesList = new List(); + + if(likes != null) + { + foreach( var liked in likes) + { + var likedInfo = new PageLikedByInformation + { + Name = liked.Name, + Mail = liked.Mail, + LoginName = liked.LoginName, + Id = liked.Id, + CreationDate = liked.CreationDate + }; + + likesList.Add(likedInfo); + } + } + + WriteObject(likesList, true); + } + } +} \ No newline at end of file From 1f809cd2e3d9b45dc8886f10aca8032bcb22e60e Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Fri, 1 Mar 2024 10:34:26 +0200 Subject: [PATCH 2/2] Update Get-PnPPageLikedByInformation.md --- documentation/Get-PnPPageLikedByInformation.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/documentation/Get-PnPPageLikedByInformation.md b/documentation/Get-PnPPageLikedByInformation.md index 7a3b6e321..01a830ba9 100644 --- a/documentation/Get-PnPPageLikedByInformation.md +++ b/documentation/Get-PnPPageLikedByInformation.md @@ -49,16 +49,16 @@ Gets the LikedBy Information of page named 'MyPage.aspx' from the subsite named ### Sample Output ```powershell -Name : Johnny Bravo +Name : User 1 Mail : Id : 14 -LoginName : i:0#.f|membership|johnny.bravo@contosso.onmicrosoft.com +LoginName : i:0#.f|membership|user1@contoso.onmicrosoft.com CreationDate : 2024-02-16 14:49:55 -Name : Nishkalank Bezawada -Mail : SuperAdmin@contosso.onmicrosoft.com +Name : User 2 +Mail : user2@contoso.onmicrosoft.com Id : 6 -LoginName : i:0#.f|membership|superadmin@contosso.onmicrosoft.com +LoginName : i:0#.f|membership|user2@contoso.onmicrosoft.com CreationDate : 2024-02-22 19:47:24 ```