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.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,741 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,389 questions
{count} votes

Accepted answer
  1. JoyZ 18,046 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 11,621 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