1

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 '[email protected]' -AddRole 'Contribute' -ClearExisting

To

Set-PnPListItemPermission -List 'Test' -Identity "TestFolder"  -User '[email protected]' -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

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnplistitempermission?view=sharepoint-ps

1 Answer 1

3

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 '[email protected]' -AddRole 'Contribute' -ClearExisting

Reference - Get-PnPListItem

1
  • 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
    Commented Feb 2, 2018 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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