Public/update-AllegisIDNSnowSchema.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 |
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 } } } } } |