Utilities/IPValidationUtility.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

using module "..\MCCA.psm1"
<#
 This function returns list of parent labels and sublabels
#>


Function Get-LableCalssification {
    Param(
        $LogFile
    )
    $SubLabels = @{}
    $ParentLabels = @{}
    $ParentSubLabelAssociation = @{}
    $ParentNameForSubLabelAssociation = @{}
    try {
        foreach ($LabelDefined in $Config["GetLabel"]) {
            $Label = $LabelDefined
            if ($($Label.ParentId)) {
                $SubLabels.add($($Label.Name), $Label)
                if ($ParentSubLabelAssociation.ContainsKey($($Label.ParentId))) {
                    $ParentSubLabelAssociation[$($Label.ParentId)].Add($($Label.Name)) #+= $($Label.Name)
                }
                else {
                    $ParentSubLabelAssociation.add($($Label.ParentId), [System.Collections.ArrayList]@()) #$($Label.Name))
                    $ParentSubLabelAssociation[$($Label.ParentId)].Add($($Label.Name))
                }
            }
            else {
                $ParentLabels.add($($Label.Name), $Label)
            }
              
        }
    
        # Setting parent name for the parent with sublabels by creating a hash table with key as
        # parent guid and value as parent name.
        if ($($($ParentSubLabelAssociation.Keys).count) -gt 0) {
            foreach ($ParentGUID in $($ParentSubLabelAssociation.Keys)) {
                foreach ($LabelDefined in $Config["GetLabel"]) {
                    if ($($LabelDefined.Guid) -eq $ParentGUID) {
                        $ParentNameForSubLabelAssociation[$ParentGUID] = $LabelDefined.Name
                    }
                }
            }
        }
    }
    catch {
        Write-Host "Error:$(Get-Date) There was an issue while running MCCA. Please try running the tool again after some time." -ForegroundColor:Red
        $ErrorMessage = $_.ToString()
        $StackTraceInfo = $_.ScriptStackTrace
        Write-Log -IsError -ErrorMessage $ErrorMessage -StackTraceInfo $StackTraceInfo -LogFile $LogFile -ErrorAction:SilentlyContinue
    }
    

    $LabelClassification = New-Object -TypeName psobject
    $LabelClassification | Add-Member -MemberType NoteProperty -Name sublabels -Value $SubLabels
    $LabelClassification | Add-Member -MemberType NoteProperty -Name parentlabels -Value $ParentLabels    
    $LabelClassification | Add-Member -MemberType NoteProperty -Name parentsublabelassociation -Value $ParentSubLabelAssociation       
    $LabelClassification | Add-Member -MemberType NoteProperty -Name parentnameforsublabelassociation -Value $ParentNameForSubLabelAssociation              
    return $LabelClassification
}