简体   繁体   中英

How can I get the “Copy Link” from a document on SharePoint Online document library using Powershell

I'm looking for a way to get the link that you get when you press copy link on a document from sharepoint online document library. I need to retrieve this link programmatically using powershell. any advice and thoughts?

Here is a picture of the link highlighted in blue.

在此处输入图片说明

Thank you

You need to use the Microsoft Graph API. There are examples and documentation around the web but it is in Beta so keep in mind the process might change.

You can use Get on the sharepoint site and see the drive objects, Then you can connect to them using the Drive ID and look at the webURL property of the files.

https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/drive

I ended up constructing the link dynamically. So Here is what I ended up doing to get the link:

  1. use the cmdlet Get-PnPListItem
  2. retrieve each UniqueID for each item in the library
  3. Here is an example

    $UniqueID = (Get-PnPListItem -id 231 -List Budget).FieldValues.UniqueID

  4. the $UniqueID = e1a1f20f-4b7d-4y16-x021-3469bde98088

Here are the link steps:

  1. https://mycompany.sharepoint.com/Site/subsite/_layouts/15/WopiFrame.aspx?sourcedoc= {
  2. e1a1f20f-4b7d-4y16-x021-3469bde98088
  3. }&action=edit

at the end just construct all steps to build your link dynamically. https://mycompany.sharepoint.com/Site/subsite/_layouts/15/WopiFrame.aspx?sourcedoc={e1a1f20f-4b7d-4y16-x021-3469bde98088}&action=edit

In the end the only id you will be changing is the unique id between the curly brackets.

Adding to what Nick says, we can use the Graph API to achieve this requirement in particular the " createLink " endpoint.

We can do a POST request with following body (or similar)

{
  "type": "edit",
  "scope": "organization"
}

and the request URL can be one of the following

  • /v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}/driveItem/createLink
  • /v1.0/sites/{site-id}/drive/items/{drive-item-id}/createLink
  • /v1.0/sites/{site-id}/drives/{drive-id}/items/{drive-item-id}/createLink

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM