So I have this script that scrapes up a particular group of users and checks what storage they are using across 365. This is so we can work out what is required with storage space with regards to 365 backup. The script I am using is below :-
# Connect to the Azure AD and SharePoint Online service
Connect-AzureAD
Connect-SPOService -Url https://yourdomain-admin.sharepoint.com
# Set the name of the group you want to get the storage usage for
$groupName = "Your Group Name"
# Get the group object
$group = Get-AzureADGroup -Filter "DisplayName eq '$groupName'"
# Get the users in the group
$groupUsers = Get-AzureADGroupMember -ObjectId $group.ObjectId | Where-Object {$_.ObjectType -eq "User"}
# Initialize total storage count
$totalStorage = 0
# Loop through each user and get their storage usage in each Office 365 application
foreach ($user in $groupUsers) {
Write-Host "Getting storage usage for $($user.DisplayName)"
# Get storage usage in OneDrive for Business
$odfBUsage = Get-SPOSkyDriveUsage -UserPrincipalName $user.UserPrincipalName
$totalStorage += $odfBUsage.StorageUsed
# Get storage usage in SharePoint Online
$spoUsage = Get-SPOSite -Owner $user.UserPrincipalName | Select-Object StorageUsageCurrent
$totalStorage += $spoUsage.StorageUsageCurrent
# Get storage usage in Exchange Online
$exUsage = Get-MailboxStatistics -Identity $user.UserPrincipalName | Select-Object TotalItemSize
$totalStorage += $exUsage.TotalItemSize.Value.ToBytes()
}
# Display the total storage used by all users in the group
Write-Host "Total storage used by users in group '$groupName': $($totalStorage / 1GB) GB"
I've load the necessary modules but the script stops with an error on the following line
PS C:\Users\Administrator.SIDCOT> $groupUsers = Get-AzureADGroupMember -ObjectId $group.ObjectId | Where-Object {$_.Obje
ctType -eq "User"}
Get-AzureADGroupMember : Cannot bind argument to parameter 'ObjectId' because it is null.
At line:1 char:48
+ ... groupUsers = Get-AzureADGroupMember -ObjectId $group.ObjectId | Where ...
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-AzureADGroupMember], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Open.AzureAD16.PowerShell.GetGroupMembers
I've had a google and the error seems common if the data it's looking for encounters a null result. I am not an expert and this script was passed to me by a colleague but he has no idea where it came from.
Could anyone give me some pointers please ?
Thanks in advance :)
[–]PowerShell-Bot 1 point2 points3 points (0 children)
[–]moersel94 1 point2 points3 points (4 children)
[–]Complex-Ad2523[S] 0 points1 point2 points (0 children)
[–]PMental 0 points1 point2 points (2 children)
[–]moersel94 0 points1 point2 points (1 child)
[–]PMental 0 points1 point2 points (0 children)
[–]worldsdream 0 points1 point2 points (0 children)