internal/functions/check/Check-UserSetRequiresUpdate.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Check-UserSetRequiresUpdate
{
    <#
        .SYNOPSIS
            Check whether a userSet list has changed.
        .DESCRIPTION
            Returns $true if userSet list has changed.
        .PARAMETER Reference
            Should always be the userSet from Azure AD (or Graph).
        .PARAMETER Difference
            Should be the defined TMF userSet.
    #>

    [CmdletBinding()]
    Param (
        [object[]] $Reference,
        [object[]] $Difference,
        [System.Management.Automation.PSCmdlet]
        $Cmdlet = $PSCmdlet
    )    
    
    process
    {
        if ($Difference.Count -eq 0 -and $Reference.Count -eq 0) { return }
        if ($Difference.Count -ne $Reference.Count) {
            return $true
        }
        
        foreach ($set in $Difference) {
            if ($set.id) {
                if ($set.id -notin $Reference.id) { return $true }
            }
            elseif ($set.getId) {
                if ($set.getId() -notin $Reference.id) { return $true }
            }

            if ($set.managerLevel) {
                if ($set.managerLevel -notin $Reference.managerLevel) {
                    return $true
                }
            }
            if ($set."@odata.type" -notin $Reference."@odata.type") {
                return $true
            }
        }
    }
}