0
  • I have a requirement to copy all SharePoint Document libraries into Azure Solutions. like copy into Azure Storage account/ CosmosDB, etc.,

I request anyone to suggest any solution or tool to copy all SharePoint Documents into Azure Blob Storage Account.

1 Answer 1

0
  • This PowerShell script shows how to download and sync documents in a SharePoint Document Library into an Azure Storage Container using CLI for Microsoft 365 and Azure CLI commands.

     $spolHostName = "https://tenant-name.sharepoint.com"
     $spolSiteRelativeUrl = "/sites/site-name"
     $spolDocLibTitle = "document-library-title"
     $azStorageAccountKey = "*****************"
     $azStorageAccountName = "azure-storage-account-name"
     $azStorageContainerName = "azure-storage-container-name"
     $localBaseFolderName = "local-base-folder-name"
    
     $localFileDownloadFolderPath = $PSScriptRoot
     $spolSiteUrl = $spolHostName + $spolSiteRelativeUrl
    
     $spolLibItems = m365 spo listitem list --webUrl $spolSiteUrl --title 
     $spolDocLibTitle --fields 'FileRef,FileLeafRef' --filter "FSObjType eq 0" -o json | ConvertFrom-Json
    
     if ($spolLibItems.Count -gt 0) {
       ForEach ($spolLibItem in $spolLibItems) {
         $spolLibFileRelativeUrl = $spolLibItem.FileRef
         $spolFileName = $spolLibItem.FileLeafRef
    
         $spolLibFolderRelativeUrl = $spolLibFileRelativeUrl.Substring(0, $spolLibFileRelativeUrl.lastIndexOf('/'))
    
     $localDownloadFolderPath = Join-Path $localFileDownloadFolderPath $localBaseFolderName $spolLibFolderRelativeUrl
    
     If (!(test-path $localDownloadFolderPath)) {
       $message = "Target local folder $localDownloadFolderPath not exist"
       Write-Host $message -ForegroundColor Yellow
    
       New-Item -ItemType Directory -Force -Path $localDownloadFolderPath | Out-Null
    
       $message = "Created target local folder at $localDownloadFolderPath"
       Write-Host $message -ForegroundColor Green
     }
     else {
       $message = "Target local folder exist at $localDownloadFolderPath"
       Write-Host $message -ForegroundColor Blue
     }
    
     $localFilePath = Join-Path $localDownloadFolderPath $spolFileName
    
     $message = "Processing SharePoint file $spolFileName"
     Write-Host $message -ForegroundColor Green
    
     m365 spo file get --webUrl $spolSiteUrl --url $spolLibFileRelativeUrl --asFile --path $localFilePath
    
     $message = "Downloaded SharePoint file at $localFilePath"
     Write-Host $message -ForegroundColor Green
       }
    
       $localFolderToSync = Join-Path $localFileDownloadFolderPath 
     $localBaseFolderName
       az storage blob sync --account-key $azStorageAccountKey --account-name $azStorageAccountName -c $azStorageContainerName -s $localFolderToSync --only-show-errors | Out-Null
    
       $message = "Syncing local folder $localFolderToSync with Azure Storage Container $azStorageContainerName is completed"
       Write-Host $message -ForegroundColor Green
     }
     else {
       Write-Host "No files in $spolDocLibTitle library" -ForegroundColor Yellow
     }
    
  • Copy files from SharePoint to Azure Blob storage using Microsoft Flow: https://www.c-sharpcorner.com/article/copy-files-from-sharepoint-to-an-azure-blob-storage-using-microsoft-flow/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.