Hi @Joao Manoel Castilho Franco ,
please try this:
$GroupName = "M365_F1"
$UserList = Import-Csv -Path "C:\temp\test_licenses_m365_F1.csv"
foreach ($User in $UserList) {
$UserPrincipalName = $User.UserPrincipalName
$Group = Get-AzureADGroup -Filter "DisplayName eq '$GroupName'"
$UserToRemove = Get-AzureADUser -Filter "UserPrincipalName eq '$UserPrincipalName'"
if ($UserToRemove -ne $null -and $Group -ne $null) {
Remove-AzureADGroupMember -ObjectId $Group.ObjectId -MemberId $UserToRemove.ObjectId
Write-Host "Removed $UserPrincipalName from $GroupName"
}
else {
Write-Host "User or Group not found: $UserPrincipalName or $GroupName"
}
}
The parameter of Remove-AzureADGroupMember
should be -MemberId
instead of -Members
.
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards Andreas Baumgarten