Hello,
I am trying to use Powershell and Group-Object to identify users who have received two license packages. Unfortunately I can’t do this no matter what I change. I think the error is really stupid but I can’t find it. Could someone tell me what the error is and the solution?
# Einzelne Lizenzen für Microsoft 365 Lizenzen
$grp_u_Microsoft365_Lic_E1_Audio_Conferencing = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E1_Audio_Conferencing" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E1 Audio Conferencing Lizenz
$grp_u_Microsoft365_Lic_E1_Exchange = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E1_Exchange" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E1 Exchange Lizenz
$grp_u_Microsoft365_Lic_E1_Forms = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E1_Forms" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E1 Forms Lizenz
$grp_u_Microsoft365_Lic_E1_OfficeMobileApps = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E1_OfficeMobileApps" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E1 Office Mobile Apps Lizenz
$grp_u_Microsoft365_Lic_E1_SharePoint = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E1_SharePoint" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E1 SharePoint Lizenz
$grp_u_Microsoft365_Lic_E1_Teams = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E1_Teams" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E1 Teams Lizenz
$grp_u_Microsoft365_Lic_E1_TK_Full = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E1_TK_Full" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E1 TK Full Lizenz
$grp_u_Microsoft365_Lic_E1_TK_Light = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E1_TK_Light" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E1 TK Light Lizenz
$grp_u_Microsoft365_Lic_E3_Audio_Conferencing = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E3_Audio_Conferencing" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E3 Audio Conferencing Lizenz
$grp_u_Microsoft365_Lic_E3_Exchange = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E3_Exchange" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E3 Exchange Lizenz
$grp_u_Microsoft365_Lic_E3_Forms = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E3_Forms" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E3 Forms Lizenz
$grp_u_Microsoft365_Lic_E3_OfficeProPlus = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E3_OfficeProPlus" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E3 Office Pro Plus Lizenz
$grp_u_Microsoft365_Lic_E3_SharePoint = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E3_SharePoint" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E3 SharePoint Lizenz
$grp_u_Microsoft365_Lic_E3_Teams = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E3_Teams" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E3 Teams Lizenz
$grp_u_Microsoft365_Lic_E3_Test = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E3_Test" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E3 Test Lizenz
$grp_u_Microsoft365_Lic_E3_TK_Full = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E3_TK_Full" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E3 TK Full Lizenz
$grp_u_Microsoft365_Lic_E3_TK_Light = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_E3_TK_Light" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für E3 TK Light Lizenz
$grp_u_Microsoft365_Lic_P1_Exchange = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_P1_Exchange" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für P1 Exchange Lizenz
$grp_u_Microsoft365_Lic_P2_Exchange = Get-ADGroupMember -Identity "grp_u_Microsoft365_Lic_P2_Exchange" -Recursive | Get-ADUser -Properties UserPrincipalName # Gruppe für P2 Exchange Lizenz
# Lizenzpakete Exchange P1
$All_ExchangeP1_Users = @($grp_u_Microsoft365_Lic_P1_Exchange)
# Lizenzpakete Exchange P2
$All_ExchangeP2_Users = @($grp_u_Microsoft365_Lic_P2_Exchange)
# Lizenzpakete Office 365 E1
$All_Office365E1_Users = @($grp_u_Microsoft365_Lic_E1_Audio_Conferencing, $grp_u_Microsoft365_Lic_E1_Exchange, $grp_u_Microsoft365_Lic_E1_Forms, $grp_u_Microsoft365_Lic_E1_OfficeMobileApps, $grp_u_Microsoft365_Lic_E1_SharePoint, $grp_u_Microsoft365_Lic_E1_Teams, $grp_u_Microsoft365_Lic_E1_TK_Full, $grp_u_Microsoft365_Lic_E1_TK_Light)
$All_Office365E1_Users = $All_Office365E1_Users | Sort-Object UserPrincipalName -Unique
# Lizenzpakete Office 365 E3
$All_Office365E3_Users = @($grp_u_Microsoft365_Lic_E3_Audio_Conferencing, $grp_u_Microsoft365_Lic_E3_Exchange, $grp_u_Microsoft365_Lic_E3_Forms, $grp_u_Microsoft365_Lic_E3_OfficeProPlus, $grp_u_Microsoft365_Lic_E3_SharePoint, $grp_u_Microsoft365_Lic_E3_Teams, $grp_u_Microsoft365_Lic_E3_Test, $grp_u_Microsoft365_Lic_E3_TK_Full, $grp_u_Microsoft365_Lic_E3_TK_Light)
$All_Office365E3_Users = $All_Office365E3_Users | Sort-Object UserPrincipalName -Unique
# Alle Lizensierte Benutzer
$All_Licensed_Users = @($All_Office365E1_Users, $All_Office365E3_Users, $All_ExchangeP1_Users, $All_ExchangeP2_Users)
# Überprüfen Sie auf Duplikate
$duplikate = $All_Licensed_Users.UserPrincipalName | Group-Object | Where-Object { $_.Count -gt 1 } | Select-Object -ExpandProperty Name
if ($duplikate) {
Write-Output "Folgende Benutzerobjekte sind in mehreren Lizenzpaketen enthalten: $duplikate"
} else {
Write-Output "Alle Benutzerobjekte sind eindeutig."
}