Skip to main content

spo file sharinglink add

Creates a new sharing link for a file

Usage

m365 spo file sharinglink add [options]

Options

-u, --webUrl <webUrl>

The URL of the site where the file is located.

--fileUrl [fileUrl]

The server- or site-relative decoded URL of the file. Specify either fileUrl or fileId but not both.

--fileId [fileId]

The UniqueId (GUID) of the file. Specify either fileUrl or fileId but not both.

--type <type>

The type of sharing link to create. Either view or edit.

--expirationDateTime [expirationDateTime]

The date and time to set the expiration. This should be defined as a valid ISO 8601 string.

--scope [scope]

The scope of link to create. Either anonymous or organization. If not specified, the default of the organization will be used.

-h, --help [help]

Output usage information. Optionally, specify which section of command's help you want to see. Allowed values are options, examples, remarks, response, full. Default is options.

--query [query]

JMESPath query string. See http://jmespath.org/ for more information and examples.

-o, --output [output]

Output type. json, text, csv, md, none. Default json.

--verbose

Runs command with verbose logging.

--debug

Runs command with debug logging.

Examples

Creates a sharing link of a specific type for a file by id.

m365 spo file sharinglink add --webUrl https://contoso.sharepoint.com --fileId daebb04b-a773-4baa-b1d1-3625418e3234 --type view

Creates a sharing link of a specific type for a file by url.

m365 spo file sharinglink add --webUrl https://contoso.sharepoint.com --fileUrl "/sites/demo/Shared Documents/Test1.docx" --type edit

Creates a sharing link of a file by url with type, scope and expirationDateTime parameter.

m365 spo file sharinglink add --webUrl https://contoso.sharepoint.com --fileUrl "/sites/demo/Shared Documents/Test1.docx" --type edit --scope anonymous --expirationDateTime "2023-01-09T16:20:00Z"

Response

{
"id": "1e581e93-609e-4077-8152-c43865db684c",
"roles": [
"read"
],
"expirationDateTime": "2023-10-01T07:00:00Z",
"hasPassword": false,
"link": {
"scope": "anonymous",
"type": "view",
"webUrl": "https://contoso.sharepoint.com/:b:/g/EbZx4QPyndlGp6HV-gvSPksBSyMcgRPtyAxqqNAeiEp1kg",
"preventsDownload": false
}
}
CTRL + M