-
Notifications
You must be signed in to change notification settings - Fork 380
Add Add-PnPFileSensitivityLabel cmdlet for assigning sensitivity labels to SharePoint files #4538
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,105 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Add-PnPFileSensitivityLabel.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Add-PnPFileSensitivityLabel | ||
--- | ||
|
||
# Add-PnPFileSensitivityLabel | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* Microsoft Graph API : One of Files.ReadWrite.All, Sites.ReadWrite.All | ||
|
||
Add the sensitivity label information for a file in SharePoint. | ||
|
||
## SYNTAX | ||
```powershell | ||
Add-PnPFileSensitivityLabel -Identity <String> -SensitivityLabelId <Guid> -AssignmentMethod <Enum> -JustificationText <string> | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
The Add-PnPFileSensitivityLabel cmdlet adds the sensitivity 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. It also takes the sensitivity label Id , assignment method and justification text values as input. | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
This example adds the sensitivity label information for the file at the specified URL. | ||
|
||
```powershell | ||
Add-PnPFileSensitivityLabel -Identity "/sites/Marketing/Shared Documents/Report.pptx" -SensitivityLabelId "b5b11b04-05b3-4fe4-baa9-b7f5f65b8b64" -JustificationText "Previous label no longer applies" -AssignmentMethod Privileged | ||
``` | ||
|
||
### Example 2 | ||
This example removes the sensitivity label information for the file at the specified URL. | ||
|
||
```powershell | ||
Add-PnPFileSensitivityLabel -Identity "/sites/Marketing/Shared Documents/Report.pptx" -SensitivityLabelId "" -JustificationText "Previous label no longer applies" -AssignmentMethod Privileged | ||
``` | ||
|
||
## PARAMETERS | ||
|
||
### -Identity | ||
The server relative path to the file, the unique identifier of the file, the listitem representing the file, or the file object itself on which we are adding the sensitivity label. | ||
|
||
```yaml | ||
Type: FilePipeBind | ||
Parameter Sets: (All) | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -SensitivityLabelId | ||
ID of the sensitivity label to be assigned, or empty string to remove the sensitivity label. | ||
|
||
```yaml | ||
Type: string | ||
Parameter Sets: (All) | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: True | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -AssignmentMethod | ||
The assignment method of the label on the document. Indicates whether the assignment of the label was done automatically, standard, or as a privileged operation (the equivalent of an administrator operation). | ||
|
||
```yaml | ||
Type: Guid | ||
Parameter Sets: (All) | ||
Accepted values: Standard, Privileged, Auto | ||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: True | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -JustificationText | ||
Justification text for audit purposes, and is required when downgrading/removing a label. | ||
|
||
```yaml | ||
Type: Guid | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
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 hidden or 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,9 @@ | ||
namespace PnP.PowerShell.Commands.Enums | ||
{ | ||
public enum SensitivityLabelAssignmentMethod | ||
{ | ||
Standard, | ||
Privileged, | ||
Auto | ||
} | ||
} |
This file contains hidden or 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,51 @@ | ||
using PnP.Core.Model.SharePoint; | ||
using PnP.PowerShell.Commands.Attributes; | ||
using PnP.PowerShell.Commands.Base; | ||
using PnP.PowerShell.Commands.Base.PipeBinds; | ||
using PnP.PowerShell.Commands.Utilities.REST; | ||
using System.Management.Automation; | ||
using System.Net.Http.Headers; | ||
|
||
namespace PnP.PowerShell.Commands.Files | ||
{ | ||
[Cmdlet(VerbsCommon.Add, "PnPFileSensitivityLabel")] | ||
[RequiredApiDelegatedOrApplicationPermissions("graph/Files.ReadWrite.All")] | ||
[RequiredApiDelegatedOrApplicationPermissions("graph/Sites.ReadWrite.All")] | ||
|
||
public class AddFileSensitivityLabel : PnPGraphCmdlet | ||
{ | ||
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true)] | ||
public FilePipeBind Identity; | ||
|
||
[Parameter(Mandatory = true)] | ||
public string SensitivityLabelId; | ||
|
||
[Parameter(Mandatory = false)] | ||
public Enums.SensitivityLabelAssignmentMethod AssignmentMethod = Enums.SensitivityLabelAssignmentMethod.Privileged; | ||
|
||
[Parameter(Mandatory = false)] | ||
public string JustificationText = string.Empty; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
var serverRelativeUrl = string.Empty; | ||
|
||
IFile file = Identity.GetCoreFile(Connection.PnPContext, this); | ||
file.EnsureProperties(f => f.VroomDriveID, f => f.VroomItemID); | ||
|
||
var requestUrl = $"https://{Connection.GraphEndPoint}/v1.0/drives/{file.VroomDriveID}/items/{file.VroomItemID}/assignSensitivityLabel"; | ||
|
||
var payload = new | ||
{ | ||
sensitivityLabelId = SensitivityLabelId, | ||
assignmentMethod = AssignmentMethod.ToString(), | ||
justificationText = JustificationText | ||
}; | ||
|
||
HttpResponseHeaders responseHeader = RestHelper.PostGetResponseHeader<string>(Connection.HttpClient, requestUrl, AccessToken, payload: payload); | ||
|
||
WriteVerbose($"File sensitivity label assigned to {file.Name}"); | ||
WriteObject(responseHeader.Location); | ||
} | ||
} | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.