microsoft / Microsoft365DSC

Manages, configures, extracts and monitors Microsoft 365 tenant configurations
https://aka.ms/M365DSC
MIT License
1.6k stars 499 forks source link

MSFT_AADGroup: Unknown variable used in Set-TargetResource #5001

Closed FJanneau closed 1 month ago

FJanneau commented 2 months ago

Description of the issue

Hello,

In MSFT_AADGroup.psm1 file, line 570, the variable $assignedLicensesGUIDs is used in a condition. As this variable is never used or declared before, the condition is always false and never executed. So I wonder if this part should be removed or if a feature is missing in case this condition should be true.

    _if ($assignedLicensesGUIDs.Length -gt 0)
    {
        Set-MgGroupLicense -GroupId $currentGroup.Id -AddLicenses $licensesToAdd -RemoveLicenses @()
    }_

Kind regards.

Microsoft 365 DSC Version

V1.24.731.1

Which workloads are affected

Azure Active Directory (Entra ID)

The DSC configuration

No response

Verbose logs showing the problem

No response

Environment Information + PowerShell Version

No response

salbeck-sit commented 2 months ago

I don't have time to test but it seems that $assignedLicensesGUIDs should be $licensesToAdd as the condition is part of ensuring that a group exists that previously didn't.

salbeck-sit commented 1 month ago

The code in question is in fact never executed. However, the scriptblock following it takes care of things, so the block of code could be removed. While at it, I tried to build unit-tests that verify that license-processing works as advertised. This in turn caused me to update the Test-TargetResource function so that DisabledPlans for each assigned licenses is processed per SkuId to clarify which license has differing DisabledPlans. I have e PR ready that fixes the above