I am trying to use the following cmdlet in the pnp module on O365 and one of the parameters for the cmdlet is -identity

-Identity The ID of the listitem, or actual ListItem object

Type:   ListItemPipeBind  
Position:   Named  
Accept pipeline input:  True 
Accept wildcard characters: False

The parameter says the ID of the listitem or the listitem object, I am trying to put the name instead of the ID

So changing -identity from

Set-PnPListItemPermission -List 'Test' -Identity 1  -User 'Test@test.com' -AddRole 'Contribute' -ClearExisting


Set-PnPListItemPermission -List 'Test' -Identity "TestFolder"  -User 'Test@test.com' -AddRole 'Contribute' -ClearExisting

The script runs on both occasions with no errors but the permission is only changed when -identity is the ID, am I missing something here?

enter image description here



By list item object, it means passing the Microsoft.SharePoint.Client.ListItem object.

You are currently passing string which will not work.

You need to use Get-PnPListItem to get the list item and then pass it to the Set-PnPListItemPermission command.

To do that, you can use it as below:

$listItem = Get-PnPListItem -List 'Test' -Id 1

or passing CAML query, something like

$listItem = Get-PnPListItem -List 'Test' -Query "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>TestFolder</Value></Eq></Where></Query></View>"

And then

Set-PnPListItemPermission -List 'Test' -Identity $listItem  -User 'Test@test.com' -AddRole 'Contribute' -ClearExisting

Reference - Get-PnPListItem

| improve this answer | |
  • Thank you very much - I tried had tried $listItem = Get-PnPListItem -List 'Test' -Query "<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>TestFolder</Value></Eq></Where></Query></View>" | select ID at an earlier point in time but your answer was perfect – Jamie_lee Feb 2 '18 at 10:54

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.