Reputation: 1
I want to automate retrieving data of all user permission on each of the available SharePoint groups of my SharePoint site, into a SharePoint list that I can use as a matrix for tracking who has access to which folder, also I want to be able to when I make edit permission on my SharePoint list matrix the change reflect sharepoint immediately and visa versa if a change occurred on SharePoint the change to be sync on the list as well,
now I can retrieve groups and users alone but I can't retrieve the groups dynamically and make an iteration to go through each group and retrieve all its users. can anyone let me know how to do this? I am new to power automated and not very familiar with its actions so I would appreciate it if you could assist me with creating this flow
Upvotes: 0
Views: 591
Reputation: 344
Here’s a step-by-step outline to achieve this using PowerShell:
Connect to SharePoint Online:
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -UseWebLogin
Retrieve All SharePoint Groups:
$groups = Get-PnPGroup
Retrieve Members of Each Group and Add to a SharePoint List:
$listName = "YourListName"
foreach ($group in $groups) {
$members = Get-PnPGroupMember -Identity $group.Title
foreach ($member in $members) {
$item = @{
"Title" = $member.Title
"Email" = $member.Email
"Group" = $group.Title
}
Add-PnPListItem -List $listName -Values $item
}
}
Make sure you have the PnP PowerShell module installed. You can install it using:
Install-Module -Name "PnP.PowerShell"
Upvotes: 0
Reputation: 238
@van Hasan try those steps:-
Use the "Send an HTTP request to SharePoint" action to get all SharePoint groups. The request should be to the endpoint /_api/web/sitegroups.
Within this loop, use another "Send an HTTP request to SharePoint" action to retrieve all users in the current group by calling /_api/web/sitegroups(Id)/users.
Update SharePoint List.
Upvotes: 0