Skip to content

New command: Apply a default sensitivity label to a document library #4716

Description

@nicodecleyre

Usage

m365 spo list sensitivitylabel ensure [options]

Description

Apply a default sensitivity label to a document library

Options

Option Description
-u, --webUrl <webUrl> The URL of the site where the library is located.
--name <name> The label name to apply to the list.
-t, --listTitle [listTitle] The title of the library on which to set the label. Specify either listTitle, listId, or listUrl but not multiple.
-l, --listId [listId] The ID of the library on which to set the label. Specify either listTitle, listId, or listUrl but not multiple.
--listUrl [listUrl] Server- or web-relative URL of the library on which to set the label. Specify either listTitle, listId, or listUrl but not multiple.

Examples

Applies a sensitivity label to a document library based on the list title

m365 spo list sensitivitylabel ensure --webUrl 'https://contoso.sharepoint.com' --listTitle 'Shared Documents' --name 'Label'

Applies a sensitivity label to a document library based on the list url

m365 spo list sensitivitylabel ensure --webUrl 'https://contoso.sharepoint.com' --listUrl '/Shared Documents' --name 'Label'

Applies a sensitivity label to a document library based on the list id

m365 spo list sensitivitylabel ensure --webUrl 'https://contoso.sharepoint.com' --listId 'b4cfa0d9-b3d7-49ae-a0f0-f14ffdd005f7' --name 'Label'

Default properties

No response

Additional Info

This can be archieved by doing:
First getting the Sensitivity Label ID which should be applied, this can be done by doing:
GET https://graph.microsoft.com/beta/security/informationProtection/sensitivityLabels, here an in code filtering should be done based on the name property.

Secondly: PATCH https://contoso.sharepoint.com/sites/testcomm/_api/web/lists(guid'[List ID]')
or PATCH https://contoso.sharepoint.com/sites/testcomm/_api/web/lists/getByTitle('[List Title]')
or PATCH https://contoso.sharepoint.com/sites/testcomm/_api/web/GetList([List server relative URL])

headers

{
     if-match: *
}

body

{
    "DefaultSensitivityLabelForLibrary": [Sensitivity label ID]
}

on success the api returns a 204 No Content

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions