Skip to content

Commit a8db710

Browse files
[New Command] - Get-PnPPageLikedByInformation (#3781)
* New-Command-Get Page LikedBy Information * Update Get-PnPPageLikedByInformation.md --------- Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
1 parent 4246c15 commit a8db710

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
title: Get-PnPPageLikedByInformation
4+
schema: 2.0.0
5+
applicable: SharePoint Online
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPPageLikedByInformation.html
8+
---
9+
10+
# Get-PnPPageLikedByInformation
11+
12+
## SYNOPSIS
13+
Returns liked-by Information of a modern page
14+
15+
## SYNTAX
16+
17+
```powershell
18+
Get-PnPPageLikedByInformation -Identity <PagePipeBind> [-Connection <PnPConnection>]
19+
```
20+
21+
## DESCRIPTION
22+
This command retrieves the LikedBy Information of a modern page.
23+
24+
25+
## EXAMPLES
26+
27+
### EXAMPLE 1
28+
```powershell
29+
Get-PnPPageLikedByInformation -Identity "MyPage.aspx"
30+
```
31+
32+
Gets the LikedBy Information of page named 'MyPage.aspx' in the current SharePoint site
33+
34+
### EXAMPLE 2
35+
```powershell
36+
Get-PnPPageLikedByInformation "MyPage"
37+
```
38+
39+
Gets the LikedBy Information of page named 'MyPage.aspx' in the current SharePoint site
40+
41+
42+
### EXAMPLE 3
43+
```powershell
44+
Get-PnPPageLikedByInformation -Identity "MyPage.aspx" -Web (Get-PnPWeb -Identity "Subsite1")
45+
```
46+
47+
Gets the LikedBy Information of page named 'MyPage.aspx' from the subsite named 'Subsite1'
48+
49+
### Sample Output
50+
51+
```powershell
52+
Name : User 1
53+
Mail :
54+
Id : 14
55+
LoginName : i:0#.f|membership|user1@contoso.onmicrosoft.com
56+
CreationDate : 2024-02-16 14:49:55
57+
58+
Name : User 2
59+
Mail : user2@contoso.onmicrosoft.com
60+
Id : 6
61+
LoginName : i:0#.f|membership|user2@contoso.onmicrosoft.com
62+
CreationDate : 2024-02-22 19:47:24
63+
```
64+
65+
## PARAMETERS
66+
67+
### -Connection
68+
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.
69+
70+
```yaml
71+
Type: PnPConnection
72+
Parameter Sets: (All)
73+
74+
Required: False
75+
Position: Named
76+
Default value: None
77+
Accept pipeline input: False
78+
Accept wildcard characters: False
79+
```
80+
81+
### -Identity
82+
The name of the page
83+
84+
```yaml
85+
Type: PagePipeBind
86+
Parameter Sets: (All)
87+
88+
Required: True
89+
Position: 0
90+
Default value: None
91+
Accept pipeline input: True (ByValue)
92+
Accept wildcard characters: False
93+
```
94+
95+
96+
97+
## RELATED LINKS
98+
99+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
100+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace PnP.PowerShell.Commands.Model
8+
{
9+
public class PageLikedByInformation
10+
{
11+
public string Name { get; set; }
12+
public string Mail { get; set; }
13+
public int Id { get; set; }
14+
public string LoginName { get; set; }
15+
public DateTime CreationDate { get; set; }
16+
}
17+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+

2+
using PnP.Core.QueryModel;
3+
using PnP.PowerShell.Commands.Base.PipeBinds;
4+
using PnP.PowerShell.Commands.Model;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Management.Automation;
8+
using System.Text;
9+
10+
namespace PnP.PowerShell.Commands.Pages
11+
{
12+
[Cmdlet(VerbsCommon.Get, "PnPPageLikedByInformation")]
13+
[OutputType(typeof(PageLikedByInformation))]
14+
public class GetPageLikedByInformation : PnPWebCmdlet
15+
{
16+
[Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0)]
17+
public PagePipeBind Identity;
18+
19+
protected override void ExecuteCmdlet()
20+
{
21+
var clientSidePage = Identity.GetPage(Connection);
22+
23+
if (clientSidePage == null)
24+
throw new Exception($"Page '{Identity?.Name}' does not exist");
25+
26+
var pageLikeInformation = clientSidePage.GetLikedByInformationAsync().GetAwaiter().GetResult();
27+
28+
var likes = pageLikeInformation.LikedBy.AsRequested();
29+
30+
var likesList = new List<PageLikedByInformation>();
31+
32+
if(likes != null)
33+
{
34+
foreach( var liked in likes)
35+
{
36+
var likedInfo = new PageLikedByInformation
37+
{
38+
Name = liked.Name,
39+
Mail = liked.Mail,
40+
LoginName = liked.LoginName,
41+
Id = liked.Id,
42+
CreationDate = liked.CreationDate
43+
};
44+
45+
likesList.Add(likedInfo);
46+
}
47+
}
48+
49+
WriteObject(likesList, true);
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)