SharePoint Online: Bulk Create Dummy Files using PowerShell

Requirement: For a testing exercise, We had to bulk upload 5000+ documents to a document library in SharePoint Online.

PnP PowerShell to Create Dummy Files in Bulk in SharePoint Online

This PowerShell script bulk uploads the given file with unique names to the root folder of a specified SharePoint Online document library. Make sure you have the Local File “C:\Temp\Dummy.docx” and the SharePoint document library already before running this script.

$SiteURL = ""
$LibraryName = "LargeLibrary"
$LocalFile= "C:\Temp\Dummy.docx"
$MaxFilesCount = 5000

Try {
    #Get the File
    $File = Get-ChildItem $LocalFile

    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive
    #$Library = Get-PnPList -Identity $LibraryName

    $FileCounter = 1
    While($FileCounter -le $MaxFilesCount)
	    $NewFileName= $File.BaseName+"_"+$FileCounter+".docx"
		    Add-PnPFile -Path $File -Folder $LibraryName -NewFileName $NewFileName | Out-Null
		    Write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
	    Write-host -f Green "New File '$NewFileName' Created ($FileCounter of $MaxFilesCount)!"
Catch {
    write-host -f Red "Error Uploading File:"$_.Exception.Message

Based on the number of files and file size, the script’s execution time varies and creates documents on the given document library.

Similarly, to bulk create a large number of list items in SharePoint Online, use: PowerShell to Bulk Add List Items in SharePoint Online using PnP-Batch

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *