12 thoughts on “Office 365 Advent Calendar – 06 Bulk-Uploading Files with Metadata to SharePoint Online”

  1. Excellent! Very nice and concise. It was what I was looking for. Two challenges… SharePoint doesn’t seem to like when there is no value even if the SP field is not mandatory. The bigger challenge I’m running into is setting the Enterprise Keywords column. I know this post is old but if you happen to see it and can write a response in less time it takes to drink a cup of coffee that would be great. If not, thanks much for posting this originally!!

    1. Hi Rob,
      found a solution for the Enterprise Keywords. You need to update the foreach($metadatacolumn…) loop as follows:

      foreach($metadatacolumn in $metadatacolumns) {
      if($metadatacolumn -eq “TaxKeyword”) {
      $values.Add($metadatacolumn, @($file.$metadatacolumn,$file.$metadatacolumn))
      } else {
      $values.Add($metadatacolumn, $file.$metadatacolumn)

      For the Enterprise Keywords (Field: TaxKeyword) the term (in the format “System|Keywords|MyTerm”) needs to be provided twice. Found this in the following article: https://www.thelazyadministrator.com/2018/08/20/manage-and-administer-sharepoint-using-sharepointpnp-powershell/
      Note that I’m only able to use a single term in my code above. There are way how it could work with multiple terms, but decided to provide this simple solution first.

  2. Hi Rene,
    Thanks for posting, this is the best solution that I have found so far.

    2 questions:

    1) Is there a preferred way to format the ‘file’ column to allow for folder/sub-folder creation? I have tried the following with no luck.

    2) Only one column of metadata populates, even when they are all set to ‘Single Line of Text’. Have you ran across this issue?

    I am using SharePoint Online.

    Thanks in advance!

    1. Hi Amon,

      haven’t got a solution for your first problem. Might work with an updated code that checks the value of the file column for a folder hierarchy and then creates it accordingly, with the last step being the upload. Will see if I can code something like this at some point.
      Second issue doesn’t sound familiar, it was working for me without any issues so far. Not sure why it doesn’t work properly for you

    2. Ok, was easier than I thought, as Add-PnPFile actually creates any folders that are provided as part of the -Folder parameter.
      Here’s the code:
      $cred = Get-Credential
      Connect-PnPOnline -Url https://mytenant.sharepoint.com -Credentials $cred
      $library = "Metadata Test"

      $files = Import-Csv filestoupload.csv
      $metadatacolumns = $files | Get-Member -MemberType 'NoteProperty' | Select-Object -ExpandProperty 'Name' | Where {$_ -ne "file"}

      foreach($file in $files) {
      $values = @{}
      foreach($metadatacolumn in $metadatacolumns) {
      $values.Add($metadatacolumn, $file.$metadatacolumn)
      $path = $file.file.split("/")
      if($path.length -eq 1) {
      Add-PnPFile -Path $file.file -Folder $library -Values $values
      } else {
      $folder = $library + "/"+($file.file -replace $path[$path.length-1],"")
      Add-PnPFile -Path $file.file -Folder $folder -Values $values

      This way it actually also works with a folder structure that is present. Let me know if any further clarification is required

      1. Hi Rene,

        Thanks so much for this!
        Very helpful and thorough and I’m able to make it work for my needs. I really appreciate your time.


  3. Hi Rene,

    Thanks for the post.

    I am getting the below error while executing your code,

    Add-PnPFile : Cannot bind argument to parameter ‘Path’ because it is null.
    At line:6 char:20
    + Add-PnPFile -Path $file.file -Folder “SPMTTEST” -Values $values

    Can you please help?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.