Hi @Raki ,
The below script would help you achieve this:
#Connect to PnP Online
connect-pnponline https://tenant.sharepoint.com/sites/test
$Library = "doc1"
#Get all root folders of the library
$RootFolders = Get-PnPFolderItem -FolderSiteRelativeUrl $Library -ItemType Folder | Where {$_.Name -ne "Forms"}
#Loop through the RootFolders
ForEach($RootFolder in $RootFolders){
$RootFolderURL = $Library+"/"+$RootFolder.Name
#Get all sub folders of the rootFolder
$Subfolders=Get-PnPFolderItem -FolderSiteRelativeUrl $RootFolderURL -ItemType Folder
#Loop through the SubFolders
ForEach($SubFolder in $SubFolders){
$SubFolderPath=$RootFolder.Name+"/"+$SubFolder.Name
write-host "Setting default column values for folder:" $SubFolderPath
Set-PnPDefaultColumnValues -List $Library -Field Agent -Value $RootFolder.Name -Folder $SubFolderPath
Set-PnPDefaultColumnValues -List $Library -Field Address -Value $SubFolder.Name -Folder $SubFolderPath
}
}
If an Answer is helpful, please click "Accept Answer" and upvote it.
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.