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 and the SharePoint document libraries exist 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 execution time of the script varies.

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply