13 thoughts on “SharePoint Folders and the Challenge of Metadata”

  1. Thank you, Sean! Really helpful article for me, as I’m new to .Net SPO development. I’m gonna print and laminate that UML diagram!

  2. Hey Sean, fantastic post! As a newbee, I can really appreciate a GURU like you and your willingness to share with the rest of us.

    I studied then ran the script in my environment and while folder get created, the metadata does not. For some reason, the folder path (relative URL) gets copied to the Title field even though they are 2 distinct fields in my CSV.

    Do you have any pointer for me?

    Thanks,
    Gilles

    1. Hi Gilles,

      Thanks for the comment and feedback. Off the top of my head, I don’t have any particular direction to steer you; I’d really need to see the CSV file you’re supplying to the script to try to understand what’s going on. Just a gut feeling, but if you’re trying to explicitly assign a “Title” as a metadata field then that might be causing you trouble. In SharePoint, “Title” tends to be a something of a special field. I don’t know for certain, though. If you wanted to send me your CSV and how the script is being invoked (i.e., the parameters you’re supplying), I could try reproducing on my end and watching everything in stepwise execution to see what’s going on.

      My email is sean@sharepointinterface.com if you wanted to send the file. No guarantees, but I could at least take a look at it. Regardless of what you decide, I wish you the best of luck in troubleshooting. I’ve found it tends to be something of a “dark art” :-)

      – Sean

  3. Hello there,
    This script is exactly what I’ve been looking for, but it has not been working for me.
    I have run the script in PowerShell 5.1 (Win11) I get the following error after entering my credentials.
    “- The ‘Connect-PnPOnline’ command was found in the module ‘PnP.PowerShell’, but the module could not be loaded. For more information, run ‘Import-Module PnP.PowerShell’.
    – Script execution halted.”

    I’ve installed PowerShell 7 and when I run it from there it give this error.
    “- The ‘Connect-PnPOnline’ command was found in the module ‘PnP.PowerShell’, but the module could not be loaded due to the following error: [Could not load file or assembly ‘Microsoft.Online.SharePoint.Client.Tenant, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’. Could not find or load a specific file. (0x80131621)]
    For more information, run ‘Import-Module PnP.PowerShell’.
    – Script execution halted.”

    Any direction you could give me on this would be greatly appreciated.

    Regards,

    Dan

    1. Hi Dan,

      Sorry to hear that you’re having troubles. I appreciate you providing some error and stack trace info, though, and I do have a suggestion for you: do you have the SharePoint Online Management Shell (https://learn.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/connect-sharepoint-online) installed along with the PnP cmdlets? If not, I would install that and give it another spin.

      That’s my quick thought. If it doesn’t work for you, let me know. Good luck!

  4. Hello there,

    This is exactly what I need, but I’m getting an access denied when I run the script. I’m the owner/creator of the site so I’m not sure why it’s saying that. Here is what the output looks like.

    0
    1
    – Access denied.
    – Script execution halted.

    Any help would be appreciated,

    Dan

    1. Hi Dan,

      Sorry to hear that you’re running into permissions issues. That said, the path to resolution is pretty clear; see https://learn.microsoft.com/en-us/answers/questions/425370/what-role-is-required-to-run-powershelll-command-i

      Trevor spells things out in the answer supplied. Generally speaking, you’re going to need more than just rights within the site, since PowerShell execution goes into administrative territory.

      I hope that helps!

      – Sean

      1. I was able to find that custom scripts had to be turned on at the site level in order to run the scripts.
        Now it shows the output

        0
        1

        and then returns to the command prompt, but none of the folders are created.
        I’m so close I can almost taste it!

        Thanks for your help with this,

        Dan

  5. Hello again,

    I’m sorry to bother you about this.
    I have successfully created the folders with this script, but it’s not updating the field I created previously for the metadata.
    The first line of my csv file has “Path” for the first column and “Classification Code” for the second.
    Am I supposed to use the field identifier instead of the label for that field?

    Any suggestions would be greatly appreciated.

    Regards,

    Dan

    1. Hi Dan. I suspect you might be encountering one or more of the conditions I described in the “So, What happened here?” section. Have you checked the case on your label? Are you trying to insert a field that would require some form of type conversion or manipulation?

      I would step through the script in VS Code and see what’s going on with your property Dictionary for each row, both before and after the value is assigned. That should give you a handle on where things might be going awry.

      1. Hello there and thanks for responding.
        Upon further testing it appears to have an issue with the name “Classification Code” when trying to add the metadata. I was able to add the data to a column called “test” and then rename it afterwards to “Classification Code”. As this is for initial setup of of some sites I should need to run it that often so changing the name after the fact is not a big deal.

        Thank you so much for this script and the help with troubleshooting.

        Regards,

        Dan

Leave a Reply to Sean McDonoughCancel reply

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

Discover more from The SharePoint Interface

Subscribe now to keep reading and get access to the full archive.

Continue reading