从Sharepoint批量导出文件路径

时间:2019-09-09 14:44:28

标签: hyperlink filepath sharepoint-online

我要将200多个超链接添加到excel文件中,以便于访问共享点文件夹。我不是手动拉出每个文件夹,而是尝试从sharepoint文件夹批量导出文件路径。有关如何执行此操作的任何想法?

1 个答案:

答案 0 :(得分:0)

我们可以使用PnP PowerShell来实现它。

#Config Variables
$SiteURL = "https://tenant.sharepoint.com/sites/lz"
$ListName = "DL0906"
$FolderRelativeURL= "/sites/lz/DL0910/Test"
$ExportFile="C:\temp\FileUrls.csv"  
#Get Credentials to connect
$Cred = Get-Credential

Try {
    #Connect to PNP Online
    Connect-PnPOnline -Url $SiteURL -Credentials $Cred

    #Get All Items from the Folder
    $CAMLQuery = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FileDirRef'/><Value Type='Text'>$FolderRelativeURL</Value></Eq></Where></Query></View>"
    $FolderItems = Get-PnPListItem -List $ListName -Query $CAMLQuery

    $FileCollection = @() 
    ForEach($Item in $FolderItems)
    {
        $ExportFileUrl = New-Object PSObject 
        $ExportFileUrl | Add-Member -MemberType NoteProperty -name "File URL" -value $Item["FileRef"]
        $FileCollection += $ExportFileUrl
    }   
    $FileCollection | Export-CSV $ExportFile -NoTypeInformation
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

引用:SharePoint Online: Get All Files from a Folder using PowerShell