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)*"

    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.



Updated solution:

We have to load the ListItemsAllFields first.


Set-PnPListItemPermission -List 'Team Reports' -Identity $folder.ListItemAllFields.Id -User $($user.Email) -AddRole 'Read' -ClearExisting 

But be carefull. $folders will contain not only the visible folders of the root folder of list. It will also contain hidden folders like attachments and items.

  • I did that before and it doesnt come up with anything for some reason. and i get "Set-PnPListItemPermission : Cannot bind argument to parameter 'Identity' because it is null". Is there a way i can list all the $folder properties? – jAC Mar 15 '18 at 19:13
  • hmm... seems like ListItemAllFields.Id is empty for some reason. I have tested it on my machine and there is no value inside. – Lutz Mar 15 '18 at 20:07
  • Yeah, not sure why it would be empty. Could i use Get-PnPListItem instead of Get-PnPFolderItem? I am trying it and looks like i could see the folders but its all guid based now instead of by name. I also only want folders in a certain directory. ListItem is showing all them regardless :/ – jAC Mar 15 '18 at 20:26
  • see my updated answer. – Lutz Mar 15 '18 at 20:35
  • you can also directly use includes parameter Get-PnPFolder -Url "<path here>" -Includes "ListItemAllFields" – san Jun 1 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.