1

I would like to create a report that contains all subsites and all associated groups and members. This is what I have so far:

Get-PnPGroup -PipelineVariable g | Get-PnPGroupMembers | ForEach {
[pscustomobject]@{
DisplayName = $_.Title
EmailAddress = $_.Email
GroupName = $g.Title
}
} | Select Displayname, EmailAddress, GroupName 

This returns all groups and members, fine. Now I would like to add the url's. According to the documentation,the Get-PnPGroup command accepts a web object from the pipeline and the has an AssociatedMemberGroup switch that only returns groups related to that.

Simply adding Get-PnPSubWebs -Recurse -PipelineVariable s in front of the code didn't help:

Get-PnPGroup : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or 
the input and its properties do not match any of the parameters that take pipeline input.

Wrapping in Foreach{} didn't work either, because:

Get-PnPGroup : The object is used in the context different from the one associated with the object.

So, I created a new connection and loaded the web object based on the url:

Get-PnPSubWebs -Recurse -PipelineVariable s | ForEach {

$webconnection = Connect-PnPOnline -Url $_.Url -Credentials $credential
$web = Get-PnPWeb -Connection $webconnection

Get-PnPGroup -Connection $webconnection -Web $web -AssociatedMemberGroup -PipelineVariable g | Get-PnPGroupMembers | ForEach {

[pscustomobject]@{
Site = $s.ServerRelativeURL
DisplayName = $_.Title
EmailAddress = $_.Email
GroupName = $g.Title
}

}  | Format-Table  -AutoSize

} 

This, in first case made the code insane slow, second, though, producing results, I still see the same context error in the output as above. Can somebody please help me out, what am I doing wrong?

Your Answer

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

Browse other questions tagged or ask your own question.