Here are steps:
1.In the SharePoint Online Management, install Microsoft.Graph module.
Install-Module -Name Microsoft.Graph
2.Find the group id of security group. Go to the Microsoft 365 admin center, navigate to "Teams & groups" -> "Active teams & groups", select the desired security group, and the group ID will be visible in the URL bar when you click on the group name.
3.Create a csv file as following picture show.
4.Run following PowerShell. Replace the path with your file in the PowerShell.
# Check that we're connected to SharePoint Online
[array]$Modules = Get-Module
If ("Microsoft.Online.Sharepoint.PowerShell" -notin $Modules.Name) {
Write-Host "Please connect to the SharePoint Online management module and restart the script."; break
}
# Connect to the Microsoft Graph
Connect-MgGraph -Scopes Directory.Read.All, Group.Read.All
# Read in allocated sizes for different group members
# The CSV file used should have columns for group, groupid, and allocation
If (Test-Path "c:\OneDriveAllocations.csv") {
[array]$OneDriveAllocations = Import-CSV -Path c:\OneDriveAllocations.csv
} Else {
Write-Host "Can't find group information to process - exiting" ; break
}
# Figure out the service domain and what this means for the root of OneDrive account URLs
$ServiceDomain = (Get-MgOrganization).verifiedDomains | Where-Object {$_.IsInitial -eq $True} | Select-Object -ExpandProperty Name
$OneDriveDomain =("https://{0}-my.sharepoint.com/personal/" -f $ServiceDomain.Split(".")[0])
$Report = [System.Collections.Generic.List[Object]]::new()
ForEach ($Group in $OneDriveAllocations) {
# Get group members and extract their user principal names
[array]$GroupMembers = Get-MgGroupMember -GroupId $Group.GroupId
$GroupMemberUPN = $GroupMembers.additionalProperties.userPrincipalName
# Calculate the quota allocation for group members (in megabytes)
[int]$NewAllocation = $Group.Allocation; $NewAllocation = $NewAllocation*1024
ForEach ($Member in $GroupMemberUPN) {
# Figure out the OneDrive site URL for the user's account
$MemberDomain = $Member.Replace(".","_")
$MemberDomain = $MemberDomain.Replace("@", "_")
$OneDriveSiteURL = $OneDriveDomain + $MemberDomain
$CurrentQuotaGB = ((Get-SPOSite -Identity $OneDriveSiteURL).StorageQuota/1024)
If ($CurrentQuotaGB -lt $Group.Allocation) {
# Current allocation is less than the quota assigned to the group, so increase it to the group allocation
Write-Host ("Updating OneDrive storage allocation for account {0} to {1}" -f $Member, $Group.Allocation)
Set-SPOSite -Identity $OneDriveSiteURL -StorageQuota $NewAllocation
$ReportLine = [PSCustomObject]@{
Guest = $Member
OneDrive = $OneDriveSiteURL
"Old Quota" = $CurrentQuotaGB
"New Quota" = $Group.Allocation }
$Report.Add($ReportLine)
} #End update quota
} #End members of a group
} #End all groups
# Show what we did
$Report | Out-GridView
5.Result:
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.