Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Command] - Get-PnPPageLikedByInformation #3781

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions documentation/Get-PnPPageLikedByInformation.md
Original file line number Diff line number Diff line change
@@ -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 <PagePipeBind> [-Connection <PnPConnection>]
```

## 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 : User 1
Mail :
Id : 14
LoginName : i:0#.f|membership|[email protected]
CreationDate : 2024-02-16 14:49:55

Name : User 2
Mail : [email protected]
Id : 6
LoginName : i:0#.f|membership|[email protected]
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)

17 changes: 17 additions & 0 deletions src/Commands/Model/PageLikedByInformation.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
52 changes: 52 additions & 0 deletions src/Commands/Pages/GetPageLikedByInformation.cs
Original file line number Diff line number Diff line change
@@ -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<PageLikedByInformation>();

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);
}
NishkalankBezawada marked this conversation as resolved.
Show resolved Hide resolved
}

WriteObject(likesList, true);
}
}
}
Loading