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

Add a Convert-ObjectToHashtable to use as a comparison #71

Closed
gaelcolas opened this issue Apr 23, 2021 · 2 comments
Closed

Add a Convert-ObjectToHashtable to use as a comparison #71

gaelcolas opened this issue Apr 23, 2021 · 2 comments
Assignees
Labels
enhancement The issue is an enhancement request.

Comments

@gaelcolas
Copy link
Member

The Compare-DscParameterState function accepts hashtable for comparing the CurrentValues with the DesiredValues.
The DscResource.Common module does not have the equivalent of ConvertTo-Hashtable for PowerShell classes (this command only accepts [CimInstances[]] as returned by MOF Based resources).

We should probably add the following function instead of adding it to every module with Class Based resources.
(like JeaDsc)

function Convert-ObjectToHashtable
{
    [OutputType([hashtable])]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [object]$Object
    )

    process
    {
        $hashtable = @{ }

        foreach ($property in $Object.PSObject.Properties.Where({ $_.Value }))
        {
            $hashtable.Add($property.Name, $property.Value)
        }

        $hashtable
    }
}
@gaelcolas
Copy link
Member Author

btw, just noticed but this might be wrong: $Object.PSObject.Properties.Where({ $_.Value })

@gaelcolas gaelcolas added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. labels Apr 23, 2021
@NicolasBn
Copy link
Member

On link to gaelcolas/Sampler#246

@johlju johlju removed the help wanted The issue is up for grabs for anyone in the community. label Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request.
Projects
None yet
Development

No branches or pull requests

3 participants