-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new command get-pnpretentionlabel (#3459)
* Add new command get-pnpretentionlabel * Added the Identity parameter and graph permissions * Added [RequiredMinimalApiPermissions("RecordsManagement.Read.All")] attribute --------- Co-authored-by: Gautam Sheth <[email protected]>
- Loading branch information
1 parent
8af971f
commit 83a0d81
Showing
5 changed files
with
266 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,73 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPRetentionLabel.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Get-PnPRetentionLabel | ||
--- | ||
|
||
# Get-PnPRetentionLabel | ||
|
||
## SYNOPSIS | ||
Gets the Microsoft Purview retention labels that are within the tenant | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Get-PnPRetentionLabel [-Identity <Guid>] [-Connection <PnPConnection>] | ||
``` | ||
|
||
## DESCRIPTION | ||
This cmdlet allows retrieval of the available Microsoft Purview retention labels in the currently connected tenant. You can retrieve all the labels or a specific label. | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Get-PnPRetentionLabel | ||
``` | ||
|
||
Returns all the Microsoft Purview retention labels that exist on the tenant | ||
|
||
### EXAMPLE 3 | ||
```powershell | ||
Get-PnPRetentionLabel -Identity 58f77809-9738-5080-90f1-gh7afeba2995 | ||
``` | ||
|
||
Returns a specific Microsoft Purview retention label by its id | ||
|
||
## PARAMETERS | ||
|
||
### -Identity | ||
The Id of the Microsoft Purview retention label to retrieve | ||
|
||
```yaml | ||
Type: Guid | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -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 | ||
``` | ||
## RELATED LINKS | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) | ||
[Microsoft Graph documentation](https://learn.microsoft.com/graph/api/informationprotectionpolicy-list-labels) |
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.Text.Json.Serialization; | ||
|
||
namespace PnP.PowerShell.Commands.Model.Graph.Purview | ||
{ | ||
public class RetentionDuration | ||
{ | ||
/// <summary> | ||
/// The type of the data. | ||
/// </summary> | ||
[JsonPropertyName("@odata.type")] | ||
public string ODataType { get; set; } = "#microsoft.graph.security.retentionDurationInDays"; | ||
/// <summary> | ||
/// Number of days. | ||
/// </summary> | ||
public int Days { 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,118 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
/// <summary> | ||
/// Describes the retention label that details how to Represents how customers can manage their data, including whether and for how long to retain or delete it." | ||
/// </summary> | ||
/// <seealso cref="https://learn.microsoft.com/en-gb/graph/api/resources/security-retentionlabel"/> | ||
namespace PnP.PowerShell.Commands.Model.Graph.Purview | ||
{ | ||
public class RetentionLabel | ||
{ | ||
/// <summary> | ||
/// The label ID is a globally unique identifier (GUID). | ||
/// </summary> | ||
public string Id { get; set; } | ||
|
||
/// <summary> | ||
/// The display name of the label. | ||
/// </summary> | ||
public string DisplayName { get; set; } | ||
|
||
/// <summary> | ||
/// Behavior during the retention period. Specifies how the behavior of a document with this label should be during the retention period. The possible values are: doNotRetain, retain, retainAsRecord, retainAsRegulatoryRecord, unknownFutureValue. | ||
/// </summary> | ||
public BehaviorDuringRetentionPeriod? BehaviorDuringRetentionPeriod { get; set; } | ||
|
||
/// <summary> | ||
/// Action after the retention period.Specifies the action to take on a document with this label applied during the retention period. The possible values are: none, delete, startDispositionReview, unknownFutureValue. | ||
/// </summary> | ||
public ActionAfterRetentionPeriod? ActionAfterRetentionPeriod { get; set; } | ||
|
||
/// <summary> | ||
/// Retention trigger information. Specifies whether the retention duration is calculated from the content creation date, labeled date, or last modification date. The possible values are: dateLabeled, dateCreated, dateModified, dateOfEvent, unknownFutureValue. | ||
/// </summary> | ||
public RetentionTrigger? RetentionTrigger { get; set; } | ||
|
||
/// <summary> | ||
/// Retention duration information. Specifies the number of days to retain the content. | ||
/// </summary> | ||
[JsonPropertyName("retentionDuration")] | ||
public RetentionDuration RetentionDuration { get; set; } | ||
|
||
/// <summary> | ||
/// Indicates if the label is in use. | ||
/// </summary> | ||
public bool? IsInUse { get; set; } | ||
|
||
/// <summary> | ||
/// Description for administrators. | ||
/// </summary> | ||
public string DescriptionForAdmins { get; set; } | ||
|
||
/// <summary> | ||
/// Description for users. | ||
/// </summary> | ||
public string DescriptionForUsers { get; set; } | ||
|
||
/// <summary> | ||
/// Information about the creator. | ||
/// </summary> | ||
[JsonPropertyName("createdBy")] | ||
public IdentitySet CreatedBy { get; set; } | ||
|
||
/// <summary> | ||
/// Date and time when the label was created. | ||
/// </summary> | ||
public DateTimeOffset CreatedDateTime { get; set; } | ||
|
||
/// <summary> | ||
/// Information about the last modifier. | ||
/// </summary> | ||
[JsonPropertyName("lastModifiedBy")] | ||
public IdentitySet LastModifiedBy { get; set; } | ||
|
||
/// <summary> | ||
/// Date and time when the label was last modified. | ||
/// </summary> | ||
public DateTimeOffset LastModifiedDateTime { get; set; } | ||
|
||
/// <summary> | ||
/// The label to be applied. Specifies the replacement label to be applied automatically after the retention period of the current label ends. | ||
/// </summary> | ||
public string LabelToBeApplied { get; set; } | ||
|
||
/// <summary> | ||
/// Default record behavior.Specifies the locked or unlocked state of a record label when it is created.The possible values are: startLocked, startUnlocked, unknownFutureValue. | ||
/// </summary> | ||
public DefaultRecordBehavior DefaultRecordBehavior { get; set; } | ||
} | ||
|
||
public enum BehaviorDuringRetentionPeriod | ||
{ | ||
DoNotRetain, | ||
Retain, | ||
RetainAsRecord, | ||
RetainAsRegulatoryRecord | ||
} | ||
|
||
public enum ActionAfterRetentionPeriod | ||
{ | ||
None, | ||
Delete, | ||
StartDispositionReview | ||
} | ||
|
||
public enum RetentionTrigger | ||
{ | ||
DateLabeled, | ||
DateCreated, | ||
DateModified, | ||
DateOfEvent | ||
} | ||
|
||
public enum DefaultRecordBehavior | ||
{ | ||
StartLocked, | ||
StartUnlocked | ||
} | ||
} |
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,38 @@ | ||
using PnP.PowerShell.Commands.Attributes; | ||
using PnP.PowerShell.Commands.Base; | ||
using PnP.PowerShell.Commands.Utilities.REST; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
|
||
namespace PnP.PowerShell.Commands.Purview | ||
{ | ||
[Cmdlet(VerbsCommon.Get, "PnPRetentionLabel")] | ||
[OutputType(typeof(IEnumerable<Model.Graph.Purview.RetentionLabel>))] | ||
[OutputType(typeof(Model.Graph.Purview.RetentionLabel))] | ||
[RequiredMinimalApiPermissions("RecordsManagement.Read.All")] | ||
public class GetAvailableRetentionLabel : PnPGraphCmdlet | ||
{ | ||
[Parameter(Mandatory = false)] | ||
public Guid Identity; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
string url; | ||
url = "/beta/security/labels/retentionLabels"; | ||
|
||
if (ParameterSpecified(nameof(Identity))) | ||
{ | ||
url += $"/{Identity}"; | ||
|
||
var labels = GraphHelper.GetAsync<Model.Graph.Purview.RetentionLabel>(Connection, url, AccessToken).GetAwaiter().GetResult(); | ||
WriteObject(labels, false); | ||
} | ||
else | ||
{ | ||
var labels = GraphHelper.GetResultCollectionAsync<Model.Graph.Purview.RetentionLabel>(Connection, url, AccessToken).GetAwaiter().GetResult(); | ||
WriteObject(labels, 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