I am using PnP Powershell and I am looking for a way to get the folder ID so i can set permissions to particular folder. Maybe i don't need to this the way I am trying so any advice would be appreciated.
$RootFolder = "/path/to/folder"
$Library = "Library Name"
$folders = Get-PnPFolderItem -FolderSiteRelativeUrl $RootFolder
# Break Inheritance on each folder and add the user rights
foreach ($folder in $folders){
$user = Get-PnPUser | Where Title -Like "*$($folder.Name)*"
$user.Email
$folder.ListItemAllFields.BreakRoleInheritance($false,$false)
$folder.Update()
$folder.Context.ExecuteQuery()
Write-Host "Inheritance broken for" $($folder.Name) -ForegroundColor Cyan
$list = Get-PnPListItem -List $Library -Id 14 # this i need to get dynamically
Set-PnPListItemPermission -List 'Team Reports' -Identity $list -User $($user.Email) -AddRole 'Read' -ClearExisting
}
The $list
variable is what i am having a to figure out the folder ID. Right now i can put it in manually and it does what I expect but I need it to filter based on the folder so I can set the permissions based on that folder name.
Thanks