SharePoint Online: PowerShell kullanarak Listeden Ekleri İndirin


Gereksinim: Ekleri SharePoint Çevrimiçi Listesinden indirin.

SharePoint Liste Öğelerinden ekler nasıl indirilir?

Microsoft SharePoint Online'daki bir listeden ek indirmeniz mi gerekiyor? Belki de ek olarak saklanan tüm belgelere liste öğeleriyle erişmeniz veya belirli bir liste öğesinden birden fazla ek indirmeniz gerekebilir. Sebep ne olursa olsun, SharePoint'ten dosya indirmek yalnızca birkaç hızlı adımda yapılabilir. Size SharePoint Online listesinden ekleri indirmenin en hızlı ve en kolay yolunu göstereyim.

Belirli bir liste öğesinin eklerini indirmek için, öğeyi görüntüleme veya düzenleme modunda açabilir, her bir eke sağ tıklayıp tarayıcı içerik menüsünden kaydetmeyi seçebilirsiniz. Bir liste öğesindeki tüm ekleri veya tüm liste öğelerini indirmek istiyorsanız, “Ağ Sürücüsünü Haritala” özelliğini kullanın. İşte nasıl:

  1. Windows Gezgini'ne gidin (Windows Tuşu + E), soldaki ağaç görünümünden "Bu Bilgisayar"a sağ tıklayın ve "Ağ Sürücüsünü Eşle"yi seçin.
  2. “Z:” gibi sürücüyü seçin ve SharePoint listenizin URL'sini girin. Örneğin, https://intranet.crescent.com/Lists/Credit/.
  3. Bu, ekler klasörüyle birlikte Windows gezgini görünümünü açar. Ekler, ek klasörü altında alt klasörler halinde düzenlenir. Liste öğesi kimliğiniz alt klasörün adı olur! Buradan, tüm ekleri yerel makinenize kopyalayıp yapıştırarak indirebilirsiniz.

Bir Liste Öğesinden ekleri indirmek için PowerShell:

SharePoint Online'daki liste öğelerine eklenen dosyaları indirme işlemini otomatikleştirmek mi istiyorsunuz? SharePoint Online listesinden ekleri indirmek için PowerShell'i nasıl kullanacağınızı size göstereyim. Belirli bir liste öğesinden SharePoint liste öğesi ekini programlı olarak indirelim.


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Download-ListItemAttachments()
{
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $ListItemID,
        [Parameter(Mandatory=$true)] [string] $DownloadPath
    )    
   Try {
        #Setup Credentials to connect
        $Cred = Get-Credential
        $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
    
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Cred

        #Get the List Item
        $List = $Ctx.Web.Lists.GetByTitle($ListName)
        $ListItem= $List.GetItemByID($ListItemID)
    
        #Get All attachments from the List Item
        $AttachmentsColl = $ListItem.AttachmentFiles
        $Ctx.Load($AttachmentsColl)
        $Ctx.ExecuteQuery()
    
        #Get each attachment
        ForEach($Attachment in $AttachmentsColl)
        {
            #Download attachment
            $FileContent = [Microsoft.SharePoint.Client.File]::OpenBinaryDirect($Ctx, $Attachment.ServerRelativeUrl)
            $FileStream = [System.IO.File]::Create($DownloadPath+$Attachment.FileName)
            $FileContent.Stream.CopyTo($FileStream)
            $FileStream.Close()
       }

        write-host  -f Green "Total List Attachments Downloaded : $($AttachmentsColl.count)"
    }
    Catch {
        write-host -f Red "Error Downloading List Item Attachments!" $_.Exception.Message
    } 
}

#Set Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$ListName="Projects"
$ListItemID="1"
$DownloadPath="C:\Temp\"

#Call the function to copy list items
Download-ListItemAttachments -SiteURL $SiteURL -ListName $ListName -ListItemID $ListItemID -DownloadPath $DownloadPath

PowerShell kullanarak Listedeki Tüm Öğelerden Ekleri İndirin:

İşte tüm öğelerden SharePoint Online liste eklerini indirmek için PowerShell.


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Download-ListAttachments()
{
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $DownloadDirectory
    )    
   Try {
        #Setup Credentials to connect
        $Cred = Get-Credential
        $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
    
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Cred

        #Get All Items from the List
        $List = $Ctx.Web.Lists.GetByTitle($ListName)
        $ListItems = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
        $Ctx.Load($ListItems)
        $Ctx.ExecuteQuery()
        
        #Create download directory if it doesn't exist
        If (!(Test-Path -path $DownloadDirectory))        
        {            
            New-Item $DownloadDirectory -type directory          
        }
        
        #Iterate through each list item
        Foreach($Item in $ListItems)
        {
            #Get All attachments from the List Item
            $AttachmentsColl = $Item.AttachmentFiles
            $Ctx.Load($AttachmentsColl)
            $Ctx.ExecuteQuery()

            #Get attachment for each list item
            ForEach($Attachment in $AttachmentsColl)
            {
                #Download attachment
                $FileContent = [Microsoft.SharePoint.Client.File]::OpenBinaryDirect($Ctx, $Attachment.ServerRelativeUrl)
                $FileName= $DownloadDirectory+$Item.id.ToString()+"_"+$Attachment.FileName
                $FileStream = [System.IO.File]::Create($FileName)
                $FileContent.Stream.CopyTo($FileStream)
                $FileStream.Close()
           }
        }

        write-host  -f Green "List Attachments Downloaded Successfully!"
    }
    Catch {
        write-host -f Red "Error Downloading List Attachments!" $_.Exception.Message
    } 
}

#Set Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$ListName="Projects"
$DownloadDirectory="C:\Temp\"

#Call the function to copy list items
Download-ListAttachments -SiteURL $SiteURL -ListName $ListName -DownloadDirectory $DownloadDirectory

SharePoint Online: PnP PowerShell'i kullanarak Liste Öğesinden Ekleri İndirin

Bu PowerShell, belirli bir liste öğesindeki tüm ekleri indirir.


#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Projects"
$ListName = "Docs"
$ItemID = "1"
$DownloadPath = "C:\Temp\"

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -Interactive

#Get the List Item
$Listitem = Get-PnPListItem -List $ListName -Id $ItemID

#Get Attachments from List Item
$Attachments = Get-PnPProperty -ClientObject $Listitem -Property "AttachmentFiles"

#Download All Attachments from List item
Write-host "Total Number of Attachments Found:"$Attachments.Count

$Attachments | ForEach-Object { 
    Get-PnPFile -Url $_.ServerRelativeUrl -FileName $_.FileName -Path $DownloadPath -AsFile 
}

PnP PowerShell kullanarak SharePoint Çevrimiçi Listesinden Ekleri İndirme

Tüm ekleri bir listeden indirelim. Bu komut dosyası, her liste öğesi için bir klasör oluşturur ve buradaki tüm ekleri indirir.


#Set Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Projects"
$ListName = "Project Docs"
$DownloadPath = "C:\Temp\"

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -Interactive

#Get all List Items
$Listitems = Get-PnPListItem -List $ListName -PageSize 500

#Iterate through List Items
ForEach($Item in $Listitems)
{
    #Get Attachments from List Item
    $Attachments = Get-PnPProperty -ClientObject $Item -Property "AttachmentFiles"

    #Download All Attachments from List item
    Write-host "Downloading Attachments from List item '$($Item.ID)', Attachments Found: $($Attachments.Count)"

    #Create directory for each list item
    $DownloadLocation = $DownloadPath+$Item.ID
    If (!(Test-Path -path $DownloadLocation)) { New-Item $DownloadLocation -type Directory | Out-Null }

    $Attachments | ForEach-Object { 
        Get-PnPFile -Url $_.ServerRelativeUrl -FileName $_.FileName -Path $DownloadLocation -AsFile -Force
    }
}

Bu, tüm liste öğelerindeki tüm ekleri yerel diske çıkarır.

Özet olarak, SharePoint Online listesinden ekleri indirmeye yönelik çeşitli yöntemleri tartıştık. Ekleri SharePoint Online listesinden indirmek, yedekleme veya başka amaçlarla önemli dosyaları SharePoint listenizden çıkarmanın yararlı bir yoludur. Bu kılavuzda özetlenen adımları izleyerek, önemli dosyaları yedekleme veya başka amaçlarla SharePoint listenizden hızlı ve kolay bir şekilde çıkarabilirsiniz.

İlgili makaleler