-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New Command] - Get-PnPPageLikedByInformation (#3781)
* New-Command-Get Page LikedBy Information * Update Get-PnPPageLikedByInformation.md --------- Co-authored-by: Gautam Sheth <[email protected]>
- Loading branch information
1 parent
4246c15
commit a8db710
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
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
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) | ||
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
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; } | ||
} | ||
} |
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
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); | ||
} | ||
} | ||
|
||
WriteObject(likesList, true); | ||
} | ||
} | ||
} |