0

We are moving document from one drive to another, before that we are checking the document to be shared with anyone or not. In this course of action we need to check "Copy Link" from the document in SharePoint Online document library is shared with anyone or not, by using Powershell.

2 Answers 2

1

Do you mean “Get a link”? enter image description here

You won’t know if the recipient has forwarded the link to other people.

You only can get unique permissions for documents: https://social.technet.microsoft.com/wiki/contents/articles/28322.how-to-get-unique-permissions-for-siteslistslibraries-for-office-365sharepoint-2013-on-prem.aspx

0

The data about who the file has been shared with (using Copy to link) is present in the SharedWithDetails or SharedWithUsersId column.

So, you can make a CAML query to get find out if the column is null or not for files using the Get-PnPListItem command as below. It will return the item's ID, Title and GUID values:

Get-PnPListItem -List Documents -Query "<View><Query><Where><IsNull><FieldRef Name='SharedWithDetails' /></IsNull></Where></Query></View>"

or

Get-PnPListItem -List Documents -Query "<View><Query><Where><IsNull><FieldRef Name='SharedWithUsersId' /></IsNull></Where></Query></View>"

If you want it for a particular file in document library, you can use the Get-PnPFile command and get the details as below:

$item = Get-PnPFile -Url "/sites/test/Shared Documents/abcd.docx" -AsListItem
Write-host $item["SharedWithDetails"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.