Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

3 thoughts on “SharePoint Online: Convert Folders to Metadata

  • Hi Salaudeen, Hope you are fine! can you please give a hint for the Sub folders as well, if I need to add Subfolders as choice column. thanks

    Reply
    • You mean, You want to use the Sub-Folder names as choices (Instead of Folders in the root of the library)? Use:

      #Parameters
      $SiteURL= “https://crescent.sharepoint.com/sites/PMO”
      $ListName = “ProjectList”
      $MetadataColumnName = “Project”

      #Connect to PnP Online
      Connect-PnPOnline -Url $SiteURL -Interactive

      #Get All Folders from the library
      $List = Get-PnPList -Identity $ListName -Includes RootFolder.Folders
      $Folders = $List.RootFolder.Folders

      $Choices = @()
      #Get 1st level Subfolders of the Folders in the library
      ForEach($Folder in $Folders | Where {$_.Name -ne “Forms”})
      {
      $SubFolders = Get-PnPProperty -ClientObject $Folder -Property Folders
      $Choices += $SubFolders | Select -ExpandProperty Name
      }
      #Get subfolder names as choices
      $Choices

      Reply
  • Thank you for sharing your knowledge.

    Reply

Leave a Reply