SharePoint Online - PnP PowerShell - Sharing Links

Daniel Chee 231 Reputation points

Hi MS Q&A,

Seeking advice and information if there are any PnP PowerShell cmdlets (not CSOM) available to identify existing Sharing Links in use similar to gaining similar output from the Settings > Site Usage > Shared with External Users > Run Report?

Cmdlets to locate existing Sharing Links to gain information on:
• the related content that Sharing Links were enabled against
• the Sharing Links details (e.g. Link URL)
• when it was initially created and by who
• to who the Sharing Link was granted to and the privileges provided by the link

In addition:
• are there any options to configure the Out-of-the-Box report to be exported a nominated location rather than the default Root Site Collection Document Library?
• options to set expiration period for other forms of Sharing Links (e.g. organisation) other than Anyone links?


Appreciate any advice or information.

Thank you.

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
7,057 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
4,889 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. David Shvartsman 6 Reputation points

    There is no PnP PowerShell to get External Sharing Infor, but the information is stored in the "Sharing Links" list in the site.
    Below is a sample PowerShell code to parse the information from "Sharing Links" list:

    $SiteURL = 'SiteURL'

    Connect-PnPOnline -Url $SiteURL -Credential $credential -IgnoreSslErrors -WarningAction Ignore

    $SharedLinks = get-pnplistitem -List "Sharing Links"

    $InvitesAll = @()
    $strCurrentTimeZone = (Get-WmiObject win32_timezone).StandardName
    $TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($strCurrentTimeZone)

    Function Get-LocalTime($UTCTime)
    $LocalTime = ""
    if ($UTCTime -ne $Null) {
    $LocalTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)
    Return $LocalTime

    ForEach ($SharedLink in $SharedLinks) {
    $SharedLinkInfo = $SharedLink['AvailableLinks'] | ConvertFrom-Json
    foreach ($Invite in $SharedLinkInfo.Invitees) {
    $InviteEmail = $Invite.Email
    $InviteOn =$Invite.InvitedOn
    $InviteBy = $users | Where {$.ID -eq $Invite.InvitedBy}
    $InviteType = $Invite.Type #1 Is Existing user, #3 New user
    if ($Invite.Type -eq 1) {
    $InviteFoundinUIL = $users | Where {$
    .Id -eq $Invite.PId}
    $InviteEmail= $InviteFoundinUIL.Email
    else {
    $InviteFoundinUIL = $users | Where {$.Email -eq $InviteEmail}
    if ($InviteFoundinUIL) {
    $inUIL = "True"
    else {
    $inUIL = "False"
    $GuestType = ""
    if ($InviteEmail -match '<tenant domain>') {
    $Type = "Internal"
    else {
    $Type = "External"
    if ($InviteFoundinUIL) {
    if ($InviteFoundinUIL.LoginName -match '') {
    $GuestType = "AzureADGuest"
    else {
    $GuestType = "urn:spo:guest"
    #Conver InvitedOn Date/Time to local Time
    if ($InviteOn -ne $Null) {
    $InviteOn = (Get-LocalTime -UTCTime $InviteOn).toString("MM/dd/yyyy HH:mm:ss")
    $InviteDate = (Get-LocalTime -UTCTime $InviteOn).toString("yyyy/MM/dd")
    If ($debug) {Write-Host "Invitation By $($InviteBy.Title) on $($InviteOn) ($($InviteType)) for $($InviteEmail) - User Found In UIL: $($inUIL) "}
    $EmployeeFound = $EmployeeLibraries | WHERE {$
    .SiteURL -eq $SiteURL -and $_.EmployeeEmail -eq $InviteBy.Email} | Select -First 1
    if ($EmployeeFound) {
    $ListURL = $EmployeeFound.EmployeeListURL
    else {
    $ListURL = ""
    $obj = New-Object PSObject
    $obj | Add-Member NoteProperty Date $InviteDate
    $obj | Add-Member NoteProperty EmployeeSiteURL $SiteURL
    $obj | Add-Member NoteProperty EmployeeListURL $ListURL
    $obj | Add-Member NoteProperty EmployeeEmail $InviteBy.Email
    $obj | Add-Member NoteProperty InvitedOn $InviteOn
    $obj | Add-Member NoteProperty InviteType $InviteType
    $obj | Add-Member NoteProperty InviteEmail $InviteEmail
    $obj | Add-Member NoteProperty inUIL $inUIL
    $obj | Add-Member NoteProperty Type $Type
    $obj | Add-Member NoteProperty GuestType $GuestType
    $InvitesAll += $obj
    else {
    Write-Host "Invitation By $($InviteBy.Title) on $($InviteOn) ($($InviteType)) for $($InviteEmail) - User Found In UIL: $($inUIL) "

    The list of all shared links is stored in the $InvitesAll array

    Happy Scripting...

    1 person found this answer helpful.
    0 comments No comments

  2. Emily Du-MSFT 29,291 Reputation points Microsoft Vendor

    @Daniel Chee

    1.Per my knowledge, there is no PnP PowerShell to list all external sharing links.

    2.There is no option to change the default location of OOTB "Share with external users" report.

    3.You could go to SharePoint admin center -> Policies -> Sharing -> More external sharing settings -> Set "Guest access to a site or OneDrive will expire automatically after this many days". If your have set an expiration time for guest access, each guest that you invite to the site or with whom you share individual files and folders will be given access for a certain number of days.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. Limitless Technology 37,751 Reputation points

    Hello @Daniel Chee

    I would recommend you the SPOExternalSharing script which can give you information about the collection and users involved as well valid time. As far as I know there is none to report on the specific links, besides CSOM.

    Seems that other community users found a different way through Audit reports (not powershell):

    Hope this helps with your query,


    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments