diff --git a/CHANGELOG.md b/CHANGELOG.md index 9914c8f2ad..862d87d9a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ # UNRELEASED +* AADUser + * Fixed issue with license assignment + FIXES [#2556](https://github.com/microsoft/Microsoft365DSC/issues/2556) * IntuneRoledefinition * Initial Release * Manage Intune Role definition @@ -33,7 +36,7 @@ * Fixed incorrect usage of Write-Information cmdLet * Fixed typos for permissions in settings.json FIXES [2553](https://github.com/microsoft/Microsoft365DSC/issues/2553) - + # 1.22.1116.1 * AADApplication diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 index e0ec8b8f4b..0ff74d5ab1 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_AADUser/MSFT_AADUser.psm1 @@ -449,8 +449,8 @@ function Set-TargetResource { $currentLicenses = @() } - $licenseDifferences = Compare-Object -ReferenceObject $LicenseAssignment -DifferenceObject $currentLicenses - if ($licensesDifferences.Length -gt 0) + [Array]$licenseDifferences = Compare-Object -ReferenceObject $LicenseAssignment -DifferenceObject $currentLicenses + if ($licenseDifferences.Length -gt 0) { $licenses = @{AddLicenses = @(); RemoveLicenses = @();} @@ -503,10 +503,10 @@ function Set-TargetResource #region Assign Licenses try { - if ($licensesDifferences.Length -gt 0) + if ($licenseDifferences.Length -gt 0) { Write-Verbose -Message "Updating License assignments with values: $(Convert-M365DscHashtableToString -Hashtable $licenses)" - Set-MgUserLicense -UserId $user.Id -AddLicenses $licenses.AddLicenses -RemoveLicenses $licenses.RemoveLicenses + Set-MgUserLicense -UserId $user.UserPrincipalName -AddLicenses $licenses.AddLicenses -RemoveLicenses $licenses.RemoveLicenses } } catch @@ -544,9 +544,13 @@ function Set-TargetResource $currentRoles = @() } - $diffRoles = Compare-Object -ReferenceObject $Roles -DifferenceObject $currentRoles - Write-Verbose -Message "Current Roles: $($currentRoles -join ',')" - Write-Verbose -Message "Desired Roles: $($Roles -join ',')" + [Array]$diffRoles = Compare-Object -ReferenceObject $Roles -DifferenceObject $currentRoles + + if ($diffRoles.Length -gt 0) + { + Write-Verbose -Message "Current Roles: $($currentRoles -join ',')" + Write-Verbose -Message "Desired Roles: $($Roles -join ',')" + } foreach ($roleDifference in $diffRoles) {