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

Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
Microsoft 365 and Office SharePoint Server Development
Windows for business Windows Server User experience PowerShell
{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= "******@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.