$actualMembers = ResolveGroupMembersToPrincipals -group $group -principalContexts $principalContexts -disposables $disposables -credential $Credential

            if($PSBoundParameters.ContainsKey('MembersToInclude'))
            {
                $MembersToInclude = [String[]]@(RemoveDuplicates -Members $MembersToInclude)

                # Resolve the names to actual principal objects.
                [System.DirectoryServices.AccountManagement.Principal[]] $membersToIncludePrincipals = ResolveNamesToPrincipals -principalContexts $principalContexts -Disposables $disposables -credential $Credential -ObjectNames $MembersToInclude

                # Check if every element in $membersToIncludePrincipals has a match in $group.Members.
                # Compare two members lists.
                foreach($expectedMember in $membersToIncludePrincipals)
                {
                    $matchFound = $false

                    foreach($groupMember in $actualMembers)
                    {
                        if($expectedMember -eq $groupMember)
                        {
                            $matchFound = $true
                            break
                        }
                    }

                    if(!$matchFound)
                    {
                        Write-Log -Message ($LocalizedData.MembersMemberMismatch -f $expectedMember.SamAccountName, "MembersToInclude", $group.SamAccountName)
                        return $false # At least one element from $MembersToInclude does not have a match. Return $false
                    }
                }
            }

            if($PSBoundParameters.ContainsKey('MembersToExclude'))
            {
                $MembersToExclude = [String[]]@(RemoveDuplicates -Members $MembersToExclude);

                # Resolve the names to actual principal objects.
                [System.DirectoryServices.AccountManagement.Principal[]] $membersToExcludePrincipals = ResolveNamesToPrincipals -principalContexts $principalContexts -Disposables $disposables -credential $Credential -ObjectNames $MembersToExclude

                foreach($expectedMember in $membersToExcludePrincipals)
                {
                    foreach($groupMember in $actualMembers)
                    {
                        if($expectedMember -eq $groupMember)
                        {
                            Write-Log -Message ($LocalizedData.MemberToExcludeMatch -f $expectedMember.SamAccountName, "MembersToExclude", $group.SamAccountName)
                            return $false  # At least one element from $MembersToExclude has a match. Return $false
                        }
                    }
                }
            }
        }
    }
    finally
    {
        DisposeAll $disposables
    }

    # All properties match. Return $true.
    return $true;
}

<#
.Synopsis
The Get-TargetResource cmdlet for Nano Server images.
#>
function Get-TargetResourceOnNanoServer
{
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]
        $GroupName,

        [System.Management.Automation.PSCredential]
        $Credential = $null
    )

    Set-StrictMode -Version Latest

    ValidateGroupName -GroupName $GroupName

    try
    {
        [Microsoft.PowerShell.Commands.LocalGroup] $group = Get-LocalGroup -Name $GroupName -ErrorAction Stop
    }
    catch [System.Exception]
    {
        if ($_.CategoryInfo.Reason -eq 'GroupNotFoundException')
        {
            # The group is not found. Return Ensure=Absent.
            return @{
                        GroupName = $GroupName;
                        Ensure = "Absent";
                    }
        }
        Throw-TerminatingError -ErrorRecord $_
    }

    # The group is found. Enumerate all group members.
    $members = [String[]](EnumerateMembersOnNanoServer -Group $group)

    # Return all group properties and Ensure="Present".
    $returnValue = @{
                        GroupName = $group.Name;
                        Ensure = "Present";
                        Description = $group.Description;
                        Members = [System.String[]] $members;
                    }
    
    return $returnValue
}

<#
.Synopsis
The Set-TargetResource cmdlet for Nano Server images.
#>
function Set-TargetResourceOnNanoServer
{
    [CmdletBinding(SupportsShouldProcess=$true)]
    param
    (
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.String]
        $GroupName,

        [ValidateSet("Present", "Absent")]
        [System.String]
        $Ensure = "Present",

        [System.String]
        $Description,

        [System.String[]]
        $Members,

        [System.String[]]
        $MembersToInclude,

        [System.String[]]
        $MembersToExclude,

        [ValidateNotNullOrEmpty()]
        [System.Management.Automation.PSCredential]
        $Credential
    )

    Set-StrictMode -Version Latest

    ValidateGroupName -GroupName $GroupName
    
    # Try to find a group by its name.
    [bool] $groupExists = $false
    try
    {
        [Microsoft.PowerShell.Commands.LocalGroup] $group = Get-LocalGroup -Name $GroupName -ErrorAction Stop
        $groupExists = $true
    }
    catch [System.Exception]
    {
        if ($_.CategoryInfo.Reason -eq 'GroupNotFoundException')
        {
            # A group with the provided name does not exist.
            Write-Log -Message ($LocalizedData.GroupDoesNotExist -f $GroupName)
        }
        else
        {
            Throw-TerminatingError -ErrorRecord $_
        }
    }

    if($Ensure -eq "Present")
    {
        # Ensure is set to "Present".
        if(-not $groupExists)
        {
            # The group with the provided name does not exist. Add a new group.
            New-LocalGroup -Name $GroupName
            Write-Verbose -Message ($LocalizedData.GroupCreated -f $GroupName)
        }
    
        # Set group properties.
        
        if($PSBoundParameters.ContainsKey('Description') -and ((-not $groupExists) -or ($Description -ne $group.Description)))
        {
            Set-LocalGroup -Name $GroupName -Description $Description
        }
        
        # NOTE: Group members can be updated in two ways..
        # 1: Supplying the Members parameter - this causes the membership to be replaced with the members defined in Members.
        #    NOTE: If Members is empty, the group membership is cleared.
        # 2: Providing MembersToInclude and/or MembersToExclude - this adds/removes members from the list.
        #    If Members is mutually exclusive with MembersToInclude and MembersToExclude
        #    If Members is not defined then MembersToInclude or MembersToExclude must contain at least one entry.
        
        if($PSBoundParameters.ContainsKey('Members'))
        {
            if($PSBoundParameters.ContainsKey('MembersToInclude') -or $PSBoundParameters.ContainsKey('MembersToEx