question

KathyBlasco-4579 avatar image
0 Votes"
KathyBlasco-4579 asked

Where can I find a DriveItem's 'ShareId'?

I am trying to gather the Sharing Link information on DriveItems to hopefully evaluate and completely remove links that are no longer needed. My attempts to remove the Sharing Links via PowerShell script all end up with the link still showing up on the item and indicating that the link it broken. Once they are 'broken' they no longer show up on my Share Links report. I was hoping that utilizing the Microsoft Graph calls that I might be able to clear out the broken links. The documentation I am trying to follow is: shares-get

It indicates there is a ShareId. Where do I find this ShareId?

It also indicates transforming the Sharing URL into a sharing token. I was not able to do this either. My Sharing link did not look like the example. My Sharing link looks like the following (changed for privacy):

https://HIDDEN.sharepoint.com/:f:/s/mytestsite/ABCKJQZ_dmVOueZa9P_9TXsB2DvXyzNkUVEKn4YFcxMoFw

In PowerShell I completed the following:

 $myurl = "https://HIDDEN.sharepoint.com/:f:/s/mytestsite/ABCKJQZ_dmVOueZa9P_9TXsB2DvXyzNkUVEKn4YFcxMoFw"
 $encoded = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($myurl))
 $myencodedshare = $encoded -replace "=*$", ""
 $myencodedshare = $myencodedshare -replace "/", "_"
 $myencodedshare = $myencodedshare -replace "\+", "-"
 $myencodedshare = "u!" + $myencodedshare

Then used that result to execute:

 get-mgshareitem -SharedDriveItemId $myencodedshare

I am getting the below error:
get-mgshareitem : The sharing token is invalid.
At line:1 char:1
+ get-mgshareitem -SharedDriveItemId $myencodedshare
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ SharedDriveIt...ndProperty = }:<>f__AnonymousType35`9) [Get-MgShareItem_List1], RestException
`1
+ FullyQualifiedErrorId : invalidRequest,Microsoft.Graph.PowerShell.Cmdlets.GetMgShareItem_List1

Any advice regarding where the ShareId can be found or creating the Sharing Token would be appreciated!


microsoft-graph-sdk
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers