-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New cmdlet Get-PnPFileRetentionLabel. (#4603)
* New cmdlet * Fix build issue --------- Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
- Loading branch information
1 parent
74ade09
commit 7bbf721
Showing
3 changed files
with
179 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,58 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPFileRetentionLabel.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Get-PnPFileRetentionLabel | ||
--- | ||
|
||
# Get-PnPFileRetentionLabel | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* Microsoft Graph API : One of Files.Read.All, Sites.Read.All, Files.ReadWrite.All, Sites.ReadWrite.All | ||
|
||
Retrieves the retention label information for a file in SharePoint. | ||
|
||
## SYNTAX | ||
```powershell | ||
Get-PnPFileRetentionLabel -Url <String> | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
The Get-PnPFileRetentionLabel cmdlet retrieves the retention label information for a file in SharePoint using Microsoft Graph. It takes a URL as input, decodes it, and specifically encodes the '+' character if it is part of the filename. | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
This example retrieves the retention label information for the file at the specified URL. | ||
|
||
```powershell | ||
Get-PnPFileRetentionLabel -Url "/sites/Marketing/Shared Documents/Report.pptx" | ||
``` | ||
|
||
This example retrieves the retention label information for the file at the specified URL. | ||
|
||
## PARAMETERS | ||
|
||
### -Url | ||
Specifies the URL of the file for which to retrieve the retention label information. | ||
|
||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: True | ||
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,57 @@ | ||
using PnP.Framework.Utilities; | ||
using PnP.PowerShell.Commands.Attributes; | ||
using PnP.PowerShell.Commands.Base; | ||
using PnP.PowerShell.Commands.Model.Graph.Purview; | ||
using PnP.PowerShell.Commands.Utilities.REST; | ||
using System; | ||
using System.Management.Automation; | ||
|
||
namespace PnP.PowerShell.Commands.Files | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "PnPFileRetentionLabel")] | ||
[RequiredApiDelegatedOrApplicationPermissions("graph/Files.Read.All")] | ||
[RequiredApiDelegatedOrApplicationPermissions("graph/Sites.Read.All")] | ||
[RequiredApiDelegatedOrApplicationPermissions("graph/Files.ReadWrite.All")] | ||
[RequiredApiDelegatedOrApplicationPermissions("graph/Sites.ReadWrite.All")] | ||
[OutputType(typeof(FileRetentionLabel))] | ||
public class GetFileRetentionLabel : PnPGraphCmdlet | ||
{ | ||
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)] | ||
public string Url = string.Empty; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
var serverRelativeUrl = string.Empty; | ||
|
||
if (Uri.IsWellFormedUriString(Url, UriKind.Absolute)) | ||
{ | ||
// We can't deal with absolute URLs | ||
Url = UrlUtility.MakeRelativeUrl(Url); | ||
} | ||
|
||
// Remove URL decoding from the Url as that will not work. We will encode the + character specifically, because if that is part of the filename, it needs to stay and not be decoded. | ||
Url = Utilities.UrlUtilities.UrlDecode(Url.Replace("+", "%2B")); | ||
|
||
Connection.PnPContext.Web.EnsureProperties(w => w.ServerRelativeUrl); | ||
|
||
var webUrl = Connection.PnPContext.Web.ServerRelativeUrl; | ||
|
||
if (!Url.ToLower().StartsWith(webUrl.ToLower())) | ||
{ | ||
serverRelativeUrl = UrlUtility.Combine(webUrl, Url); | ||
} | ||
else | ||
{ | ||
serverRelativeUrl = Url; | ||
} | ||
|
||
var file = Connection.PnPContext.Web.GetFileByServerRelativeUrl(Url); | ||
file.EnsureProperties(f => f.VroomDriveID, f => f.VroomItemID); | ||
|
||
var requestUrl = $"v1.0/drives/{file.VroomDriveID}/items/{file.VroomItemID}/retentionLabel"; | ||
|
||
var results = RequestHelper.Get<FileRetentionLabel>(requestUrl); | ||
WriteObject(results, true); | ||
} | ||
} | ||
} |
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,64 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace PnP.PowerShell.Commands.Model.Graph.Purview | ||
{ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
public class FileRetentionLabel | ||
{ | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("retentionSettings")] | ||
public RetentionSettings RetentionSettings { get; set; } | ||
|
||
[JsonPropertyName("isLabelAppliedExplicitly")] | ||
public bool IsLabelAppliedExplicitly { get; set; } | ||
|
||
[JsonPropertyName("labelAppliedDateTime")] | ||
public DateTime LabelAppliedDateTime { get; set; } | ||
|
||
[JsonPropertyName("labelAppliedBy")] | ||
public LabelAppliedBy LabelAppliedBy { get; set; } | ||
} | ||
|
||
public class RetentionSettings | ||
{ | ||
[JsonPropertyName("behaviorDuringRetentionPeriod")] | ||
public string BehaviorDuringRetentionPeriod { get; set; } | ||
|
||
[JsonPropertyName("isDeleteAllowed")] | ||
public bool IsDeleteAllowed { get; set; } | ||
|
||
[JsonPropertyName("isRecordLocked")] | ||
public bool IsRecordLocked { get; set; } | ||
|
||
[JsonPropertyName("isMetadataUpdateAllowed")] | ||
public bool IsMetadataUpdateAllowed { get; set; } | ||
|
||
[JsonPropertyName("isContentUpdateAllowed")] | ||
public bool IsContentUpdateAllowed { get; set; } | ||
|
||
[JsonPropertyName("isLabelUpdateAllowed")] | ||
public bool IsLabelUpdateAllowed { get; set; } | ||
} | ||
|
||
public class LabelAppliedBy | ||
{ | ||
[JsonPropertyName("user")] | ||
public User User { get; set; } | ||
} | ||
|
||
public class User | ||
{ | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
|
||
[JsonPropertyName("displayName")] | ||
public string DisplayName { get; set; } | ||
} | ||
|
||
} | ||
|