Get SharePoint Link using PowerShell

Michael Tschirner 21 Reputation points
2021-11-08T09:25:58.097+00:00

Hello,

I have an automated Task generating a documentation for me and saves the File to an already shared SharePoint Folder.
Is it possible to gather the Document Link using PowerShell to be able to use it in an E-Mail sent at the end for example?

Best regards and thank you for your help.

Microsoft 365 and Office SharePoint For business Windows
Windows for business Windows Server User experience PowerShell
{count} votes

Accepted answer
  1. JoyZ 18,111 Reputation points
    2021-11-09T02:12:31.137+00:00

    @Michael Tschirner ,

    PnP PowerShell to get file URL in SharePoint Online specific folder:

    #Set Variables  
    $SiteURL= "https://tenant.sharepoint.com/sites/Team1"  
    $ListName="Documents"  
    $prefix="https://tenant.sharepoint.com"  
      
    #Connect to PNP Online  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
       
    #Get All Items from the specific folder - In batches of 500  
    $ListItems = Get-PnPListItem -List $ListName -FolderServerRelativeUrl "/sites/Team1/Shared%20Documents/Folder1027" -PageSize 500  
       
    #Loop through List Items and Get File URL  
    $Results=@()  
    ForEach($Item in $ListItems)  
    {  
        $Results += New-Object PSObject -Property @{  
        FileName =   $Item.FieldValues['FileLeafRef']  
        FileURL = $prefix + $Item.FieldValues['FileRef']  
        }  
    }  
    $Results  
    

    Result for your reference:
    147555-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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 additional answer

Sort by: Most helpful
  1. Sreeju Nair 12,666 Reputation points
    2021-11-08T10:50:12.357+00:00

    Yes, you can use Powershell to get thel links for documents stored in a document library. Refer the following sample

    https://www.sharepointdiary.com/2018/05/get-file-url-in-sharepoint-online-document-library-using-powershell.html

    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.