0

I am quite new to Power Automate and need your assistance.

I have around 30 communication sites and would like to set an AAD security group "xyz" as owner of all 30 communication sites. Since this scenario will repeat pretty often in the future I would like to save some time and browsing trough all the sites one-by-one manually.

This is how my plan looks like:

  1. Have a custom list in my teamsite where me and my colleagues will add the URL of the communication site and the name of the AAD group/ID of that group.
  2. Have a Power Automate running every time a new item is created and set the permissions.

So far I found out that I need to use the action "Send an HTTP request to SharePoint". My experience with Power Automate is very small and I hope to get some tips from you.

2 Answers 2

0

You could try to add site collection admin to multiple sites from a CSV file using PowerShell as a workaround.

PowerShell:

Import-Module Microsoft.Online.SharePoint.PowerShell
 
#Parameters
$TenantAdminURL = "https://crescent-admin.sharepoint.com"
$CSVFilePath = "C:\Temp\SiteCollectionAdmin.csv"
 
Try {
    #Connect to Admin Center
    Connect-SPOService -Url $TenantAdminURL
 
    #Get data from the CSV file
    $CSVData = Import-Csv $CSVFilePath
 
    #Iterate through each row in the CSV
    ForEach($Row in $CSVData)
    {
        Try{
            #Add Site collection Admin
            Set-SPOUser -site $Row.SiteURL -LoginName $Row.SiteCollectionAdmin -IsSiteCollectionAdmin $True | Out-Null
            Write-host "Added Site collection Administrator to $($Row.SiteURL)" -f Green
        }
        Catch {
            write-host -f Yellow "`tError Adding Site Collection Admin to $($Row.SiteURL) :" $_.Exception.Message
        }
    }
}
Catch {
    write-host -f Red "`tError:" $_.Exception.Message
}

CSV file:

enter image description here

For Reference: Add Site Collection Admin to Multiple Sites from a CSV File using PowerShell

0

This answer could certainly be more polished but I think it'll meet your needs

  1. Create a SP list that contains the site URL and ObjectID enter image description here

  2. Create an automated workflow using the When an item is created trigger along with a Get Item action to get the actual metadata required.

  3. Create two string variables, one containing the Site URL field and one that concatenates c:0o.c|federateddirectoryclaimprovider| with the Group ObjectID field enter image description here

  4. Send a http request to get the ID of the Owners SharePoint group. Method = GET, URI = _api/web/SiteGroups?$filter=substringof(%27Owners%27,LoginName)&$select=Id

this assumes there is only one group that contains the word "Owners" in the name.

  1. Parse the JSON from the previous action (do a test run of the flow before this step and copy the output to use as a template for the JSON schema) enter image description here

  2. Send a HTTP request to add the AAD group to the owners SharePoint group of the site.

Method: POST

URI: _api/Web/SiteGroups/GetById(Id)/Users (Id is from the output of the Parse JSON action and is Id not id)

Headers: { "accept": "application/json;odata=nometadata", "content-type": "application/json;odata=verbose" }

Body: { "__metadata": { "type": "SP.User" }, "LoginName": varGroupIDClaim } enter image description here

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.