Question

I have been able to export Groups and users in this format

Groups Users

GroupA User A; User A1

GroupB UserB; User B1

Using this code below

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
 
#Get All Groups from Site - Exclude system Groups
$Groups = Get-PnPGroup | Where-Object {$_.OwnerTitle -ne "System Account"}
$GroupData=@()
 
#Get Group Details
ForEach($Group in $Groups)
{
    #Get Group data
    $GroupData += New-Object PSObject -Property ([ordered]@{
    "Group Name" = $Group.Title
    "Users" = $Group.Users.Title -join "; "
    })
}
$GroupData
 
#Export Users data to CSV file
$GroupData | Export-Csv -NoTypeInformation $CSVFile

But what i'm after is

Groups Users

GroupA User A

GroupA User A1

GroupB UserB

GroupB User B1

Is this achievable and if yes how can i do that in powershell?

Thanks in advance

Était-ce utile?

La solution

You could change it to this:

ForEach($Group in $Groups)
{
    #Get Group data
    foreach($user in $Group.users){
    $GroupData += New-Object PSObject -Property ([ordered]@{
    "Group Name" = $Group.Title
    "Users" = $user.Title
    })
 }
}
#Export Users data to CSV file
$GroupData | Export-Csv -NoTypeInformation $CSVFile
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top