Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek-llm-67b-chat· DeepSeekHugging Face Arena Human Preference 55K

Using PowerShell, I want to download hundreds of 1GB files from Microsoft 365 SharePoint…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmixtral-8x7b-instruct-v0.1’s answer.
  1. User

    Using PowerShell, I want to download hundreds of 1GB files from Microsoft 365 SharePoint Online.

  2. DeepSeek Assistant

    You can use the SharePoint Online PowerShell module to download files from SharePoint Online. Here is an example of how you can download a file from a SharePoint Online site:

    # Import the SharePoint Online Management Shell module
    Import-Module SharePointPnPPowerShellOnline
    
    # Connect to SharePoint Online
    Connect-PnPOnline -Url <site URL> -Credentials (Get-Credential)
    
    # Set the file path and name
    $filePath = "C:\download\file.txt"
    $fileName = "file.txt"
    
    # Download the file
    Get-PnPFile -Url <file URL> -Path $filePath
    

    Note that this will only download one file at a time. If you have hundreds of files to download, you will need to loop through a list of file URLs and use the Get-PnPFile command in a loop. This can take a long time, so you may want to consider using a tool that can download files in parallel, such as PowerShell's Start-Job command.

    Also, keep in mind that downloading large files can consume a lot of network bandwidth and may affect the performance of the SharePoint Online site. You should perform these operations during off-peak hours if possible, and make sure that you have sufficient network bandwidth to handle the downloads.

  3. User

    I don't have a list of file names. I want to download every file in the folder I specify. I think 3 parallel download threads would work well for my resources. I'm using the newest PowerShell and have all the modules installed.

  4. DeepSeek Assistant

    You can use the SharePoint Online PowerShell module to download all the files in a folder from SharePoint Online. Here's an example of how you can download all the files in a folder using 3 parallel download threads:

    # Import the SharePoint Online Management Shell module
    Import-Module SharePointPnPPowerShellOnline
    
    # Connect to SharePoint Online
    Connect-PnPOnline -Url <site URL> -Credentials (Get-Credential)
    
    # Set the folder path
    $folderPath = "/sites/<site name>/<library name>/<folder name>"
    
    # Get all the files in the folder
    $files = Get-PnPFolderItem -FolderSiteRelativeUrl $folderPath | Where-Object { $_.File.ServerRelativeUrl -ne $null }
    
    # Define a function to download a file
    function Download-File {
        param([string]$filePath, [string]$fileName)
    
        $fullFilePath = "$filePath\$fileName"
        Get-PnPFile -Url $fileName -Path $fullFilePath
    }
    
    # Create a list to store the file paths and names
    $filePathsAndNames = @()
    
    # Loop through the files and add the file paths and names to the list
    foreach ($file in $files) {
        $filePathsAndNames += @{
            FilePath = "C:\download\"
            FileName = $file.Name
        }
    }
    
    # Create an array of jobs
    $jobs = 1..3 | ForEach-Object {
        Start-Job -ScriptBlock {
            foreach ($file in $using:filePathsAndNames) {
                Download-File -FilePath $file.FilePath -FileName $file.FileName
            }
        }
    }
    
    # Wait for all the jobs to complete
    Wait-Job -Job $jobs
    
    # Get the results of the jobs
    $results = Receive-Job -Job $jobs
    
    # Display the results
    Write-Output $results
    

    This script will download all the files in the specified folder using 3 parallel download threads. You can adjust the number of threads by changing the value of the jobs variable.

    Keep in mind that downloading large files can consume a lot of network bandwidth and may affect the performance of the SharePoint Online site. You should perform these operations during off-peak hours if possible, and make sure that you have sufficient network bandwidth to handle the downloads.

  5. User

    Will the downloaded file names be preserved? I need them to stay the same.

  6. DeepSeek Assistant

    Yes, the downloaded file names will be preserved. In the example script I provided, the Get-PnPFile command is used with the -Path parameter to specify the output file path, and the -Url parameter to specify the file URL. The -Url parameter is set to the file name, which is retrieved from the Name property of the File object. This will ensure that the file names are preserved when the files are downloaded.

    For example, if the file name in the SharePoint Online library is "file.txt", the downloaded file will also be named "file.txt".

    It's worth noting that if there are duplicate file names in the folder, the downloaded files will also have duplicate file names. In this case, you may want to add a timestamp or some other identifier to the file names to avoid conflicts.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.