0

I am in the process of moving files to Sharepoint Online. Some of the files will have a share assigned to them (obtained via the 'Copy Link' option) in the format

https://myorg.sharepoint.com/:t:/s/mysite/SOME-lONg?StringOfCharsAndNumbers456778

I want to get a list of all links using the PnP Powershell Framework but cannot find the field in the ListItem or File object that contains the information. If i select the file in Sharepoint Online, i can see a link icon which has tooltip '1 link giving access' in the 'Has Access' Info panel.

I can get the relative URL information (https://myorg.sharepoint.com/mysite/mydocs/folder1/test.txt)

My script is as follows:

#Get Credentials
$creds = Get-Credential -UserName $user -Message "Enter password."

#Connect
Connect-PnPOnline –Url $site –Credentials $creds

#Get All Items to see which one i want
Get-PnPListItem -List $docLibrary

#get more info for my test file which has ID = 295
$checkItem = Get-PnPListItem -List $docLibrary -Id 295

#See all field values for the check item
$checkItem.FieldValues

I cannot see the link information in any of the field values.

I have also tried the File object but again, cannot obviously see where the information is.

$checkFile = Get-PnpFile -Url $link

Note: the $link in the above line is the relative URL

Is this possible using the PnP Framework and do i just need to dig further into the object to get what i need or is it not possible.

Thanks

0

I was able to find a C# solution which uses the Microsoft.SharePoint.Client.ObjectSharingInformation.GetObjectSharingInformation method thanks to this post:

https://www.c-sharpcorner.com/blogs/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom Thanks to @Srikanta Barik

For those of you looking for a similar solution, here is my code:

SecureString ss = new SecureString();
foreach (var cc in pwd)
{
  ss.AppendChar(cc);
}
var creds = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(user, ss);

Microsoft.SharePoint.Client.ClientContext context = new Microsoft.SharePoint.Client.ClientContext(siteUrl);
context.Credentials = creds;
Microsoft.SharePoint.Client.Web w = context.Web;

//Load Web
context.Load(w);
context.ExecuteQuery();

//get list
Microsoft.SharePoint.Client.List list = w.Lists.GetByTitle(doclib);

//create a query to limit to 100 for now
Microsoft.SharePoint.Client.CamlQuery query = Microsoft.SharePoint.Client.CamlQuery.CreateAllItemsQuery(1000);
Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(query);

//load items
context.Load(items);
context.ExecuteQuery();

//loop through items
Microsoft.SharePoint.Client.ObjectSharingInformation sharinginfo = null;
foreach (Microsoft.SharePoint.Client.ListItem item in items)
{
  sharinginfo = Microsoft.SharePoint.Client.ObjectSharingInformation.GetObjectSharingInformation(context, item, false, true, false, true, true, true, true);
  context.Load(sharinginfo);
  context.ExecuteQuery();

  if (sharinginfo != null && sharinginfo.SharingLinks != null)
  {
    foreach (Microsoft.SharePoint.Client.SharingLinkInfo linkinfo in sharinginfo.SharingLinks)
    {
      
      if (!string.IsNullOrEmpty(linkinfo.Url))
      {        
        //export full relative file name and link
        Console.WriteLine("FileRef: {0}", item.FieldValues["FileRef"]);
        Console.WriteLine("Sharing Link Url: {0}", linkinfo.Url);
      }
    }
  }
}

The C# solution is fine for me and i wont continue to find the equivalent PS one using Pnp or similar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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