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

Add new command get-pnpretentionlabel #3459

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
50 changes: 50 additions & 0 deletions documentation/Get-PnPRetentionLabel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
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 [-Connection <PnPConnection>]
```

## DESCRIPTION
This cmdlet allows retrieval of the available Microsoft Purview retention labels in the currently connected tenant.

## EXAMPLES

### EXAMPLE 1
```powershell
Get-PnPRetentionLabel
```

Returns all the Microsoft Purview retention labels that exist on the tenant

### -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)
17 changes: 17 additions & 0 deletions src/Commands/Model/Graph/Purview/RetentionDuration.cs
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; }
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
}
}
118 changes: 118 additions & 0 deletions src/Commands/Model/Graph/Purview/RetentionLabel.cs
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
}
}
25 changes: 25 additions & 0 deletions src/Commands/Purview/GetRetentionLabel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using PnP.PowerShell.Commands.Base;
using PnP.PowerShell.Commands.Base.PipeBinds;
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))]
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
public class GetAvailableRetentionLabel : PnPGraphCmdlet
reshmee011 marked this conversation as resolved.
Show resolved Hide resolved
{
protected override void ExecuteCmdlet()
{
string url;

url = "/beta/security/labels/retentionLabels";

var labels = GraphHelper.GetResultCollectionAsync<Model.Graph.Purview.RetentionLabel>(Connection, url, AccessToken).GetAwaiter().GetResult();
WriteObject(labels, true);
}
}
}
Loading