Skip to content
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
53 changes: 53 additions & 0 deletions documentation/Get-PnPFileSensitivityLabelInfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
Module Name: PnP.PowerShell
schema: 2.0.0
applicable: SharePoint Online
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPFileSensitivityLabelInfo.html
external help file: PnP.PowerShell.dll-Help.xml
title: Get-PnPFileSensitivityLabelInfo
---

# Get-PnPFileSensitivityLabelInfo

## SYNOPSIS
Retrieves the sensitivity label information for a file in SharePoint.

## SYNTAX
```powershell
Get-PnPFileSensitivityLabelInfo -Url <String>
```

## DESCRIPTION

The Get-PnPFileSensitivityLabelInfo cmdlet retrieves the sensitivity label information for a file in SharePoint. 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 sensitivity label information for the file at the specified URL.

```powershell
Get-PnPFileSensitivityLabelInfo -Url "https://contoso.sharepoint.com/sites/Marketing/Shared Documents/Report.pdf"
```

This example retrieves the sensitivity label information for the file at the specified URL.

## PARAMETERS

### -Url
Specifies the URL of the file for which to retrieve the sensitivity 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)
29 changes: 29 additions & 0 deletions src/Commands/Files/GetFileSensitivityLabelInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.SharePoint.Client;
using PnP.PowerShell.Commands.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using System.Threading.Tasks;

namespace PnP.PowerShell.Commands.Files
{

[Cmdlet(VerbsCommon.Get, "PnPFileSensitivityLabelInfo")]
public class GetFileSensitivityLabelInfo: PnPAdminCmdlet
{
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
public string Url = string.Empty;
protected override void ExecuteCmdlet()
{
// 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"));

var fileSensitivityLabelInfo = Tenant.GetFileSensitivityLabelInfo(Url);
AdminContext.Load(fileSensitivityLabelInfo);
AdminContext.ExecuteQueryRetry();
WriteObject(new Model.SharePoint.SPOFileSensitivityLabelInfo(fileSensitivityLabelInfo));
}
}
}
28 changes: 28 additions & 0 deletions src/Commands/Model/SharePoint/SPOFileSensitivityLabelInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.Online.SharePoint.TenantAdministration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PnP.PowerShell.Commands.Model.SharePoint
{
public class SPOFileSensitivityLabelInfo
{
public string LabelId { get; set; }

public string DisplayName { get; set; }

public bool ProtectionEnabled { get; set; }

public string ParentLabelId { get; set; }

public SPOFileSensitivityLabelInfo(FileSensitivityLabelInfo label)
{
DisplayName = label.DisplayName;
LabelId = label.LabelId;
ProtectionEnabled = label.ProtectionEnabled;
ParentLabelId = label.ParentLabelId;
}
}
}