SharePoint Online - PnP PowerShell - Sharing Links

Daniel Chee 276 Reputation points
2021-09-30T04:44:29.813+00:00

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?

Example:
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?

136581-image.png

Appreciate any advice or information.

Thank you.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,952 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.
5,576 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. David Shvartsman 16 Reputation points
    2022-09-30T19:54:08.697+00:00

    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 '.onmicrosoft.com') {
    $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...

    3 people found this answer helpful.

  2. Emily Du-MSFT 48,176 Reputation points Microsoft Vendor
    2021-09-30T08:29:58.6+00:00

    @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.

    Reference:
    https://support.microsoft.com/en-us/office/manage-guest-expiration-for-a-site-25bee24f-42ad-4ee8-8402-4186eed74dea?ui=en-us&rs=en-us&ad=us


    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.

    1 person found this answer helpful.
    0 comments No comments

  3. Limitless Technology 39,721 Reputation points
    2021-09-30T13:14:10.36+00:00

    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.

    https://social.technet.microsoft.com/Forums/sharepoint/en-US/da871ab8-9cb2-4d90-8940-c06b9e7e4c32/list-of-all-shared-links-in-the-sharepoint-online-tenant?forum=sharepointgeneral

    Seems that other community users found a different way through Audit reports (not powershell):
    https://social.technet.microsoft.com/Forums/sharepoint/en-US/da871ab8-9cb2-4d90-8940-c06b9e7e4c32/list-of-all-shared-links-in-the-sharepoint-online-tenant?forum=sharepointgeneral

    Hope this helps with your query,

    -----------

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

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.