I have 300 folders in SharePoint for each vendor. Each month I will generate 300 pdf invoices and have to upload them into each specific folder. I want to avoid manually uploading each invoice to 300 different folders. Is there a way to automate this?

The folders are named the name of the vendor. Each folder contains a column for their "ILV" number. The ILV number is also included in the name of the pdf that will be uploaded. So I was thinking maybe there is a way to problematically add the pdf to the correct folder via the vendor ILV number. But I am new to SharePoint and programming and I do not really know how to get started.

Ex. Folder Name: Test Company Document to Upload Name: 2020Jan--ILV0834 ILV: ILV0834

Test document I have already manually uploaded

1 Answer 1


I made a test script using PnP PowerShell which will be helpful to you.

You may need to install PnP first.

#Config Variables
$SiteURL = ""
$Cred = Get-Credential -UserName $adminUPN -Message "Type the password."
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred

#Get All the files which has names containing ILV
$Files=Get-ChildItem -Path C:\Users\Administrator\Documents |Where-Object {$_.Name -CLike "*ILV*.txt"}

foreach ($File in $Files) {

    #Get The ILV value inside the file name
    $folder=$File.Name.substring($File.Name.IndexOf("ILV"), 7)
    #Get the corresponding folder using the ILV number. In my test it is the Name field, you can change it to another column name according to your needs
    $DestinationFolder=Get-PnPFolder -List "Shared Documents" |Where-Object {$_.Name -eq $folder} 
    $FolderPath="Shared Documents\"+$DestinationFolder.Name

    #Upload File to Folder
    Add-PnPFile -Path $File.FullName -Folder $FolderPath -ErrorAction Stop


As I am testing under the Shared Documents library, so I used it in Get-PnPFolder and Add-PnPFile. Remember to change it with your library name.

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.