microsoft / DSCParser

Allows the conversion of DSC scripts into PSObject for analysis purposes
MIT License
29 stars 19 forks source link

ConvertTo-DscObject busted again with nested properties in some cases #34

Open ricmestre opened 1 year ago

ricmestre commented 1 year ago

It seems that sometimes ConvertTo-DscObject still misbehaves, take a look at the blueprint at the bottom then check this, the Settings property inside $Resource has other properties inside that should be actually be nested inside Settings.SettingInstance (such as Value or odataType)

PS C:\> $Resource.Settings  

Name                           Value
----                           -----
CIMInstance                    MSFT_MicrosoftGraphdeviceManagementConfigurationSetting
SettingInstance                {CIMInstance, choiceSettingValue}
Value                          device_vendor_msft_policy_config_updatev83diff~policy~cat_edgeupdate~cat_applications_pol_defaultcreatedesktopshortcut_0
SettingDefinitionId            device_vendor_msft_policy_config_updatev83diff~policy~cat_edgeupdate~cat_applications_pol_defaultcreatedesktopshortcut
odataType                      #microsoft.graph.deviceManagementConfigurationChoiceSettingInstance

But in this case Settings.SettingInstance is actually empty where it shouldn't.

PS C:\> $Resource.Settings.SettingInstance

Name                           Value
----                           -----
CIMInstance                    MSFT_MicrosoftGraphDeviceManagementConfigurationSettingInstance
choiceSettingValue

Blueprint

# Generated with Microsoft365DSC version 1.23.705.1
# For additional information on how to use Microsoft365DSC, please visit https://aka.ms/M365DSC
param (
    [parameter()]
    [System.Management.Automation.PSCredential]
    $Credential
)

Configuration Custom
{
    param (
        [parameter()]
        [System.Management.Automation.PSCredential]
        $Credential
    )

    if ($null -eq $Credential)
    {
        <# Credentials #>
        $Credscredential = Get-Credential -Message "Credentials"

    }
    else
    {
        $CredsCredential = $Credential
    }

    $OrganizationName = $CredsCredential.UserName.Split('@')[1]

    Import-DscResource -ModuleName 'Microsoft365DSC' -ModuleVersion '1.23.705.1'

    Node localhost
    {
        IntuneSettingCatalogCustomPolicyWindows10 "IntuneSettingCatalogCustomPolicyWindows10-TEST"
        {
            Assignments          = @();
            Credential           = $Credscredential;
            Description          = "Test";
            Ensure               = "Present";
            Id                   = "495a239d-4367-474f-86e8-225d9f6bbe11";
            Name                 = "Setting Catalogue- Block MS Edge Shortcuts";
            Platforms            = "windows10";
            Settings             = @(
                MSFT_MicrosoftGraphdeviceManagementConfigurationSetting{
                    SettingInstance = MSFT_MicrosoftGraphDeviceManagementConfigurationSettingInstance{
                        choiceSettingValue = MSFT_MicrosoftGraphDeviceManagementConfigurationChoiceSettingValue{
                            Value = 'device_vendor_msft_policy_config_updatev83diff~policy~cat_edgeupdate~cat_applications_pol_defaultcreatedesktopshortcut_0'
                        }
                        SettingDefinitionId = 'device_vendor_msft_policy_config_updatev83diff~policy~cat_edgeupdate~cat_applications_pol_defaultcreatedesktopshortcut'
                        odataType = '#microsoft.graph.deviceManagementConfigurationChoiceSettingInstance'
                    }
                }
            );
            Technologies         = "mdm";
        }
    }
}

Custom -ConfigurationData .\ConfigurationData.psd1 -Credential $Credential
ricmestre commented 12 months ago

@nikcharlebois Just to let you know this is still happening with latest version.

ricmestre commented 10 months ago

@nikcharlebois Any chance in looking at this? I had a call early this morning where a manager told me that they are creating all policies as Settings Catalog but in order to use our solution we need to have this bug fixed otherwise they won't consider using DSC at all.

ricmestre commented 10 months ago

Here's another test resource which also has the same problem IntuneDeviceConfigurationKioskPolicyWindows10

        IntuneDeviceConfigurationKioskPolicyWindows10 "IntuneDeviceConfigurationKioskPolicyWindows10-IntuneDeviceConfigurationKioskPolicyWindows10_1"
        {
            ApplicationId                       = $IntuneApplicationId;
            Assignments                         = @(
                MSFT_DeviceManagementConfigurationPolicyAssignments{
                    dataType = '#microsoft.graph.groupAssignmentTarget'
                    deviceAndAppManagementAssignmentFilterType = 'none'
                    groupId = 'b0b8fd3f-af2a-453b-be57-80182d599f02'
                }
                MSFT_DeviceManagementConfigurationPolicyAssignments{
                    dataType = '#microsoft.graph.exclusionGroupAssignmentTarget'
                    deviceAndAppManagementAssignmentFilterType = 'none'
                    groupId = '053dc89a-be83-411a-bad3-909904b7239e'
                }
            );
            CertificateThumbprint               = $IntuneCertThumbprint;
            DisplayName                         = "IntuneDeviceConfigurationKioskPolicyWindows10_1";
            EdgeKioskEnablePublicBrowsing       = $False;
            Ensure                              = "Present";
            Id                                  = "7fea73fd-20d3-439a-9fa4-73955e082dc5";
            KioskBrowserDefaultUrl              = "http://bing.com";
            KioskBrowserEnableEndSessionButton  = $False;
            KioskBrowserEnableHomeButton        = $True;
            KioskBrowserEnableNavigationButtons = $False;
            KioskProfiles                       = @(
                MSFT_MicrosoftGraphwindowsKioskProfile{
                    AppConfiguration = MSFT_MicrosoftGraphWindowsKioskAppConfiguration{
                        odataType = '#microsoft.graph.windowsKioskSingleWin32App'
                        Win32App = MSFT_MicrosoftGraphWindowsKioskWin32App{
                            AppType = 'unknown'
                            AutoLaunch = $False
                            ClassicAppPath = 'msedge.exe'
                            EdgeKiosk = 'https://domain.com'
                            EdgeKioskType = 'publicBrowsing'
                            EdgeNoFirstRun = $True
                            StartLayoutTileSize = 'hidden'
                        }
                    }
                    ProfileId = '17f9e980-3435-4bd5-a7a1-ca3c06d0bf2c'
                    ProfileName = 'profile'
                    UserAccountsConfiguration = @(
                        MSFT_MicrosoftGraphWindowsKioskUser{
                            odataType = '#microsoft.graph.windowsKioskAutologon'
                        }
                    )
                }
            );
            TenantId                            = $OrganizationName;
            WindowsKioskForceUpdateSchedule     = MSFT_MicrosoftGraphwindowsKioskForceUpdateSchedule{
                RunImmediatelyIfAfterStartDateTime = $False
                StartDateTime = '2023-04-15T23:00:00.0000000+00:00'
                DayofMonth = 1
                Recurrence = 'daily'
                DayofWeek = 'sunday'
            };
        }
ykuijs commented 7 months ago

Fixed in PR #36

ykuijs commented 7 months ago

Issue can be closed