Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge-Array doesn't appear to be merging #31

Closed
martincaddick opened this issue Dec 3, 2024 · 4 comments
Closed

Merge-Array doesn't appear to be merging #31

martincaddick opened this issue Dec 3, 2024 · 4 comments

Comments

@martincaddick
Copy link

Awesome work Yorick.

Am I doing something wrong or is this the expected result?

image

image

And this was the end result.

image

@ykuijs
Copy link
Owner

ykuijs commented Dec 3, 2024

Hi @martincaddick, a few important comments:

  1. This function is an old function that was created 1,5 years ago. Since then we have moved to a new method based on the ObjectGraphTools module. However, we had to leave the function in the module because there were implementations still using it.

  2. However in both the old and new methods, when merging an array the code needs to have an identifier that can be used to determine match the same instance in the two arrays. For example, if you have two arrays $array1=@( @{ Item1 = 1 }, @{ Item2 = 2 }) and $array2=@( @{ Item1 = 1 }, @{ Item2 = 2 })`. The code needs to know that Item1 in both arrays are the same and Item2 are the same. That is why we are using specific keys to match instances: Some objects already have an Identity or Id parameter which are unique and can be used. If that is not the case, you have to add a parameter called UniqueId and provide a unique value. Later on, DSC is filtering out this parameter when compiling the DSC configuration. For example:

My1stResource = @(
    @{
        UniqueID = "MyObject1"
        Parameter1 = 'Test'
        Parameter2 = $false
        THE REST OF YOUR SETTINGS
    }
    @{
        UniqueID = "MyObject2"
        Parameter1 = 'Demo'
        Parameter2 = $true
        THE REST OF YOUR SETTINGS
    }
)

$My2ndResource = @(
    @{
        UniqueID = "MyObject2"
        Parameter1 = 'DemoEdit'
        Parameter2 = $false
        THE REST OF YOUR SETTINGS
    }
)

When merging these two, just the 2nd object in the first array is updated with the values in the 2nd array, since those UniqueID parameter values are matching.

  1. The ODSettings resource should not be an hashtable inside of an array. That resource can only be specified once, visible by the fact that it has the IsSingleInstance property. See here. So in this case, you should remove the array notation and just leave the hashtable:
Settings = @{
    ALL OF YOUR SETTINGS
}

instead of

Settings = @(
    @{
        ALL OF YOUR SETTINGS
    }
)

@martincaddick
Copy link
Author

@ykuijs Makes perfect sense and when I remove the hashtable it works as intended. Very nice.

Then I tried to work out why I had a hashtable inside the array.

I started with this and found I needed to change 'Configuration .\OD' to 'Configuration OD' in order to make Convert-M365DSCExportToPowerShellDataFile work. Then it produced the psd1 which I didn't even check before trying it. For some reason the Convert put it in a hashtable.

Side note, I also need to change the '.\OD' at the bottom of the script in order to get it to create the mof files.

# Generated with Microsoft365DSC version 1.24.731.1
# For additional information on how to use Microsoft365DSC, please visit https://aka.ms/M365DSC
param (
)

Configuration .\OD
{
    param (
    )

    $OrganizationName = $ConfigurationData.NonNodeData.OrganizationName

    Import-DscResource -ModuleName 'Microsoft365DSC' -ModuleVersion '1.24.731.1'

    Node localhost
    {
        ODSettings "ODSettings"
        {
            ApplicationId                             = $ConfigurationData.NonNodeData.ApplicationId;
            BlockMacSync                              = $False;
            CertificateThumbprint                     = $ConfigurationData.NonNodeData.CertificateThumbprint;
            DisableReportProblemDialog                = $False;
            DomainGuids                               = @();
            Ensure                                    = "Present";
            ExcludedFileExtensions                    = @();
            GrooveBlockOption                         = "OptOut";
            IsSingleInstance                          = "Yes";
            NotificationsInOneDriveForBusinessEnabled = $True;
            NotifyOwnersWhenInvitationsAccepted       = $False;
            ODBAccessRequests                         = "Unspecified";
            ODBMembersCanShare                        = "Unspecified";
            OneDriveForGuestsEnabled                  = $False;
            OneDriveStorageQuota                      = 1048576;
            OrphanedPersonalSitesRetentionPeriod      = 365;
            TenantId                                  = $OrganizationName;
            TenantRestrictionEnabled                  = $False;
        }
    }
}

.\OD -ConfigurationData .\ConfigurationData.psd1

@ykuijs
Copy link
Owner

ykuijs commented Dec 4, 2024

Good to hear!

The Convert-M365DSCExportToPowerShellDataFile function is a very rough first draft of this function that has some issues. We are currently working on an update of that function to make it much more usable and reliable, testing all values and comparing them against the schema. That way we will make sure the generated data files is correct.

However, there is no ETA known yet......aiming for as soon as possible 😉

@martincaddick
Copy link
Author

Merge-Array works as advertised. New issue #32 created for the export of ODSettings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants