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.
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
The data about who the file has been shared with (using
Copy to link) is present in the
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>"
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"]