Has anyone written a PowerShell script that takes metadata from the top folder and sets the metadata to sub folders and documents

Glenn Skinner 1 Reputation point
2022-08-10T13:08:25.473+00:00

We have a library with a folder for each year then under the year with a number of folders and under each folder can be up to 12 subfolders all storing various different documents. For some reason the subfolders and documents have not inherited the metadata from the top folder.

So the structure is as follows

Library> Year Folder i.e. 2022

                      Folder A (Has metadata)  

                           sub folder (no metadata)  

                           sub folder (no metadata)  

                                 sub folder (no metadata)  

                    Folder B (Has metadata)  

                           sub folder (no metadata)  

                           sub folder (no metadata)  

                                 sub folder (no metadata)  

each sub folder can have x amount of docs in it and i need the metadata on folder A to be updated in those sub folders and then the metadata in folder B to update the folders below that folder.

This can't be done manually as I have so many folders and documents pushing on 800,000 in total

I'm a relative novice to PowerShell so anything simple will be appreciated

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,003 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,157 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,626 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,586 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Raytheon 76 Reputation points
    2022-08-11T07:51:22.86+00:00

    Hi @Glenn Skinner
    I will recommend you to use pnp powershell to reach your requirement. Please refer to following code

    #Parameters  
    $SiteURL = "https://xxx.sharepoint.com/sites/test"  
    $ListName = "SPDocuments"  
    $CreatedBy= "xxx@xxxx.com"  
       
    #Connect to PnP Online  
    Connect-PnPOnline -Url $SiteURL -Interactive  
        
    #Get the all subfolders in folder A  
    $folders = Get-SPOFolderItem -FolderSiteRelativeUrl "/SPDocuments/2022/A" -ItemType Folder   
        
    #Update document properties  
    foreach($folder in $folders){  
    	Set-PnPListItem -List $ListName -Identity $folder.Id -Values @{"Author" = $CreatedBy}  
    }  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  2. Haidet Berhane 1 Reputation point
    2022-11-15T21:37:07.887+00:00

    Were you ever able to find a solutions. I gave it a shot, I have a halfway descent script that is working but it does need a little work. I need help if you solved it.


  3. Eugene Harley 0 Reputation points
    2024-12-02T18:16:03.8366667+00:00

    I know this has been answered with a proposed solution.

    I would recommend you investigate using Document Sets, there whole reason for being is to do what you are asking for.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.