Public/compare-AllegisIDNtransforms.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
function compare-AllegisIDNtransforms ($sourceOrg,$destOrg,$sourceAuthHeader,$destAuthHeader,$mapping,$change=$false){
    $sourcetransforms=get-AllegisIDNtransform -orgName $sourceOrg -accessToken $sourceAccessToken
    $desttransforms=get-AllegisIDNtransform -orgName $destOrg -accessToken $destAccessToken
    $converted=@()
    foreach ($transform in $sourcetransforms.items){
        $temp=$transform | convertto-json -Depth 100
        foreach ($map in $mapping.GetEnumerator()){
            $temp=$temp -replace $map.name , $map.value
        }
        $converted+=$temp     
    }
    $sources=get-AllegisIDNsource -orgName $destOrg -accessToken $destAccessToken

    foreach ($transform in $converted){
        $pstransform=$transform | ConvertFrom-Json
        #if ($pstransform.id -eq 'Location-CITY'){break}
        $strArray=($transform -split '\r?\n').Trim()
        foreach ($line in $strArray.where{$_ -like "*sourceName*"}){
            $name=$line -replace  '"sourceName":', ''
            $name=($name -replace '"','').trim()
            if ($name -notin $sources.name){write-warning "destination missing $name"}
        }
        $destps=$desttransforms.items.where{$_.id -eq $pstransform.id}
        $destjson=$destps | convertto-json -Depth 100
        if ($destjson -eq $null){
            "$($pstransform.id) - new-AllegisIDNtransform -orgName $destOrg -accessToken `$destAccessToken -transform `$transform"
            if ($change){
                $confirmation = Read-Host "Are you Sure You Want To Proceed:"
                if ($confirmation -eq 'y') {
                    new-AllegisIDNtransform -orgName $destOrg -accessToken $destAccessToken -transform $transform
                }                
            }
        }else{
            $transform=$transform.replace('�','')
            $destjson=$destjson.replace('�','')
            $diff=Compare-Object $transform.Split("`n") $destjson.Split("`n") -CaseSensitive
            if ($diff -ne $null){
                $diff | ft -Wrap
                "$($pstransform.id) - update-AllegisIDNtransform -orgName $destOrg -accessToken `$destAccessToken -name '$($pstransform.id)' -transform `$transform"
                if ($change){
                    #$transform
                    $confirmation = Read-Host "Are you Sure You Want To Proceed:"
                    if ($confirmation -eq 'y') {
                        update-AllegisIDNtransform -orgName $destOrg -accessToken $destAccessToken -name "$($pstransform.id)" -transform $transform
                    }
                }
            }
        }
        #$destjson=$transform | convertto-json -Depth 100
    }
}