Question

Following one-liner failed

Get-PnPGroup | where-Object {$_.title -eq 'test account'} | Set-PnPListItemPermission -Identity 1 -List "Accounts" -AddRole "Read" -Group $_.id

yielding error

Set-PnPListItemPermission : Cannot bind argument to parameter 'Group' because it is null.
At line:1 char:139
+ ...  "Read" -Group $_.id
+                    ~~~~~
    + CategoryInfo          : InvalidData: (:) [Set-PnPListItemPermission], ParameterBindingV 
   alidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,SharePointPnP.Po 
   werShell.Commands.Lists.SetListItemPermission

However, by breaking the pipe into 2 commands it works

$group = Get-PnPGroup | where-Object {$_.title -eq 'test account'} 
Set-PnPListItemPermission -Identity 1 -List "Accounts" -AddRole "Read" -Group $group.id 

How to run the command in one pipeline?

Était-ce utile?

La solution

You're missing a foreach-object around Set-PnPListItemPermission

Get-PnPGroup | where-Object {$_.title -eq 'test account'} | Foreach-Object {Set-PnPListItemPermission -Identity 1 -List "Accounts" -AddRole "Read" -Group $_.id}

But also be aware that the only thing you gain by putting it on one line is:

  • Harder to debug
  • Slower execution
  • Not potentially overwriting variable
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top