Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Get-PnPFileSharingLink and Get-PnPFolderSharingLink does not return anything for shared files/folders #3912

Closed
5 tasks
AndersRask opened this issue Apr 25, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@AndersRask
Copy link

Reporting an Issue or Missing Feature

Get-PnPFileSharingLink
and
Get-PnPFolderSharingLink
does not return anything even when files/folders are shared

Expected behavior

When calling the cmdlets
Get-PnPFileShareingLink
and
Get-PnPFolderSharingLink

I expected to get sharing link kinds for the files/folders (including LinkKind for review sharing according to feature #2949 )

When I call the [Microsoft.SharePoint.Client.ObjectSharingInformation]::GetObjectSharingInformation(..) I get the 5 standard sharing links.

What am I doing wrong?

Actual behavior

Nothing is returned when calling the cmdlets. If I call the cmdlets with invalid data, they return "Item not found" (expected)

Steps to reproduce behavior

connect-pnponline -url "https://contoso.sharepoint.com/sites/test" -interactive
get-pnplistitem -List Documents | % { Get-PnPFileSharingLink -FileUrl $_["FileRef"]}

(nothing is returned even though several files in the doclib are shared)

If I instead call the static method GetObjectSharingInformation(..) i get the link (and all other data left out for this example for brevity)

$ctx = Get-PnPContext
get-pnplistitem -List Documents | ? { $_["FSObjType"] -eq 0 } | % {
$SharingInfo = [Microsoft.SharePoint.Client.ObjectSharingInformation]::GetObjectSharingInformation($Ctx, $_, $false, $false, $false, $true, $true, $true, $true)
        $ctx.Load($SharingInfo)
        $ctx.ExecuteQuery()
$SharingInfo.SharingLinks | % { $_.Url }}

Example output that shows links are shared:

https://contoso.sharepoint.com/:i:/r/sites/test/Shared%20Documents/breach.png?csf=1&web=1
https://contoso.sharepoint.com/:w:/r/sites/test/Shared%20Documents/Document.docx?d=w584a9b0646104a9a95bdc58c446262e8&csf=1&web=1
https://contoso.sharepoint.com/:w:/r/sites/test/Shared%20Documents/Document1.docx?d=wb9ccccfd34d942ba8d0586671fd4e66b&csf=1&web=1

for the folder version, it is the same. If i use the above code, a link is shared
get-pnplistitem -List Documents | ? { $_["FSObjType"] -eq 1 } | % { Get-PnPFolderSharingLink -Folder $_["FileRef"]}
(nothing is returned even though folders are shared)

What is the version of the Cmdlet module you are running?

2.4.44 nightly PnP.PowerShell

PSVersion 7.4.2

Which operating system/environment are you running PnP PowerShell on?

  • [ x] Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify
@AndersRask AndersRask added the bug Something isn't working label Apr 25, 2024
@gautamdsheth
Copy link
Collaborator

Hmm , not sure.

Works for me :

image

Also, I am using the "new" Share dialog to share files and folders like this:

image

This cmdlet to retrieve information for the links generated via this dialog.

Does that clear things ? Maybe try it this way for a certain file and check ?

@reshmee011
Copy link
Contributor

reshmee011 commented May 5, 2024

@AndersRask , the Get-PnPFileSharingLink and Get-PnPFolderSharingLink return info only when there is an actual link, the format is different, if you go to the "Manage Access" , there will be a links, otherwise it does not return anything if there are no links, although it might have created unique permissions for the file or folder. I started looking into it only 2 weeks ago and not sure whether behaviour changed over the past. I am pondering on the best way to report sharing information. Most probably we need another cmdlet for Get-PnPFileSharingInfo using endpoing

/_api/web/lists/getbytitle('listname')/items(itemid)/GetSharingInformation$select=permissionsInformation&$Expand=permissionsInformation

@gautamdsheth: please share your views.

image

@Barbarur
Copy link

Barbarur commented May 6, 2024

MS changed the way how files are shared, MC706173. Now when you invite a user to access the file. This gets direct permissions instead of creating a shared link.
Maybe that's your case?

@reshmee011
Copy link
Contributor

reshmee011 commented May 6, 2024

Thanks @Barbarur : I don't use sharing that much except and was re exploring after a couple of years to understand functionality and clearly I missed the update MC706173. The update makes sense though confusing as unique permissions are still set on folders, files or items without the sharing link.

@reshmee011
Copy link
Contributor

@AndersRask : I have updated my blog post https://reshmeeauckloo.com/posts/powershell-get-sharing-links-sharepoint/ to include a comparison using CSOM, the PnP cmdlets and REST endpoint. However CSOM only returns all sharing information unfortunately.

@Barbarur
Copy link

Barbarur commented May 6, 2024

@reshmee011 it's even more weird actually. The new sharing is when you use click on "Share" and then "Invite". But if you use the "Copy link" function, the classic sharing link is still created.
So depending on how you share. User gets direct permissions or through the Shared Link.

@reshmee011
Copy link
Contributor

@Barbarur , thanks for explaining the new sharing versus classic sharing. Wonder if it is a feature MS needs to work on to stop the sharing links being created.

@AndersRask
Copy link
Author

MS changed the way how files are shared, MC706173. Now when you invite a user to access the file. This gets direct permissions instead of creating a shared link. Maybe that's your case?

Hi @Barbarur
you are exactly right!

It works fine when I explicitly use the link.

Microsoft managed to get people even more confused than before with that update :)

this ticket can be closed

@AndersRask
Copy link
Author

I was getting access denied when trying to fetch sharing links for a customer.
Tracking down the code it led me to the List shared method in REST API. Here I noticed that application access is not supported!
https://learn.microsoft.com/en-us/graph/api/insights-list-shared?view=graph-rest-1.0&tabs=http

image

I made a feature request on their repo, but I think this would be a good thing to add to the documentation!

Issue:
microsoftgraph/msgraph-sdk-powershell#2785

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants