Skip to content

Commit 71363e6

Browse files
gautamdshethGautam Sheth
and
Gautam Sheth
authored
Feature: added new cmdlet Get-PnPFileSensitivityLabelInfo (pnp#3994)
* Feature: added new cmdlet Get-PnPFileSensitivityLabelInfo * Update SPOFileSensitivityLabelInfo.cs --------- Co-authored-by: Gautam Sheth <gautam.sheth@staffbase.com>
1 parent 636bc84 commit 71363e6

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
schema: 2.0.0
4+
applicable: SharePoint Online
5+
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPFileSensitivityLabelInfo.html
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
title: Get-PnPFileSensitivityLabelInfo
8+
---
9+
10+
# Get-PnPFileSensitivityLabelInfo
11+
12+
## SYNOPSIS
13+
Retrieves the sensitivity label information for a file in SharePoint.
14+
15+
## SYNTAX
16+
```powershell
17+
Get-PnPFileSensitivityLabelInfo -Url <String>
18+
```
19+
20+
## DESCRIPTION
21+
22+
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.
23+
24+
## EXAMPLES
25+
26+
### Example 1
27+
This example retrieves the sensitivity label information for the file at the specified URL.
28+
29+
```powershell
30+
Get-PnPFileSensitivityLabelInfo -Url "https://contoso.sharepoint.com/sites/Marketing/Shared Documents/Report.pdf"
31+
```
32+
33+
This example retrieves the sensitivity label information for the file at the specified URL.
34+
35+
## PARAMETERS
36+
37+
### -Url
38+
Specifies the URL of the file for which to retrieve the sensitivity label information.
39+
40+
```yaml
41+
Type: String
42+
Parameter Sets: (All)
43+
44+
Required: True
45+
Position: Named
46+
Default value: None
47+
Accept pipeline input: True
48+
Accept wildcard characters: False
49+
```
50+
51+
## RELATED LINKS
52+
53+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.SharePoint.Client;
2+
using PnP.PowerShell.Commands.Base;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Management.Automation;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace PnP.PowerShell.Commands.Files
11+
{
12+
13+
[Cmdlet(VerbsCommon.Get, "PnPFileSensitivityLabelInfo")]
14+
public class GetFileSensitivityLabelInfo: PnPAdminCmdlet
15+
{
16+
[Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)]
17+
public string Url = string.Empty;
18+
protected override void ExecuteCmdlet()
19+
{
20+
// 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.
21+
Url = Utilities.UrlUtilities.UrlDecode(Url.Replace("+", "%2B"));
22+
23+
var fileSensitivityLabelInfo = Tenant.GetFileSensitivityLabelInfo(Url);
24+
AdminContext.Load(fileSensitivityLabelInfo);
25+
AdminContext.ExecuteQueryRetry();
26+
WriteObject(new Model.SharePoint.SPOFileSensitivityLabelInfo(fileSensitivityLabelInfo));
27+
}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.Online.SharePoint.TenantAdministration;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace PnP.PowerShell.Commands.Model.SharePoint
9+
{
10+
public class SPOFileSensitivityLabelInfo
11+
{
12+
public string LabelId { get; set; }
13+
14+
public string DisplayName { get; set; }
15+
16+
public bool ProtectionEnabled { get; set; }
17+
18+
public string ParentLabelId { get; set; }
19+
20+
public SPOFileSensitivityLabelInfo(FileSensitivityLabelInfo label)
21+
{
22+
DisplayName = label.DisplayName;
23+
LabelId = label.LabelId;
24+
ProtectionEnabled = label.ProtectionEnabled;
25+
ParentLabelId = label.ParentLabelId;
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)