Public/update-AllegisIDNSnowSchema.ps1

function update-AllegisIDNSnowSchema ($idnOrg, $snowOrg, $IDNaccesstoken, $snowCred)
{
    $sources=get-AllegisIDNsource -orgName $idnOrg -accessToken $IDNaccesstoken
    $sysuserschema=get-AllegisSnowSchema -environment $snoworg -table 'sys_user' -cred $snowcred
    $SPschema=get-AllegisSnowSchema -environment $snoworg -table 'x_sapo_iiq_connect_sysuser' -cred $snowcred
    foreach ($source in $sources.where{$_.sourceConnectorName -eq 'ServiceNow'})
    {
        $importSchema=get-AllegisIDNsourceSchemaImport -orgName $idnOrg -sourceid $source.id -accessToken $IDNaccesstoken
        $createSchema=get-AllegisIDNsourceSchema -orgName $idnOrg -sourceid $source.id -accessToken $IDNaccesstoken -usage 'Create'
        $importDiff=compare-object ($importSchema.attributes.name.trim() | Sort-Object) ($sysuserschema.trim() | Sort-Object)
        $createDiff=compare-object ($createSchema.fields.name.trim() | Sort-Object) ($SPschema.trim() | Sort-Object)
        foreach ($attr in $importDiff.where{$_.InputObject.length -ne 0})
        {
            if ($attr.SideIndicator -eq '<='){
                #remove
                $confirmation = Read-Host "remove $($attr.InputObject) from $($source.name) import schema"
                if ($confirmation -eq 'y') {
                    remove-AllegisIDNsourceSchemaImportAttribute -orgName $idnOrg -sourceid $source.id -accessToken $IDNaccesstoken -name $attr.InputObject
                }
            }else{
                #add
                $confirmation = Read-Host "add $($attr.InputObject) to $($source.name) import schema"
                if ($confirmation -eq 'y') {
                    new-AllegisIDNsourceSchemaImportAttribute -orgName $idnOrg -sourceid $source.id -accessToken $IDNaccesstoken -name $attr.InputObject -type 'string'
                }
            }
        }
        if (-not $source.sourceConnected){continue}
        foreach ($attr in $creatediff.where{$_.InputObject.length -ne 0})
        {
            if ($attr.SideIndicator -eq '<='){
                #remove
                $confirmation = Read-Host "remove $($attr.InputObject) from $($source.name) create schema"
                if ($confirmation -eq 'y') {
                    remove-AllegisIDNsourceSchemaAttribute -orgName $idnOrg -sourceid $source.id -accessToken $IDNaccesstoken -attribute $attr.InputObject
                }
            }else{
                #add
                $confirmation = Read-Host "add $($attr.InputObject) to $($source.name) create schema"
                if ($confirmation -eq 'y') {
                    new-AllegisIDNsourceSchemaAttribute -orgName $idnOrg -sourceid $source.id -accessToken $AccessToken -attribute $attr.InputObject
                }
            }
        }
    }
}