Public/copy-AllegisSNOWtoIDN.ps1

function copy-AllegisSNOWtoIDN ($snoworg, $snowcred, $snowfilter, $IDNorg, $IDNsourceid, $IDNClientID, $IDNClientKey, $IDNaccesstoken){
    if (!!$IDNClientID -and !!$IDNClientKey){
        $header = get-AllegisIDNBasicAuthHeader -IDNClientID $IDNClientID -IDNClientKey $IDNClientKey
    }elseif(!!$accesstoken){
        $header=get-AllegisIDNprivateHeader $IDNaccesstoken
    }
    if ($snowfilter -notlike "*u_nick_name*"){$snowfilternew=$snowfilter + "^u_nick_nameISNOTEMPTY"}else{$snowfilternew=$snowfilter}
    $snowusers=get-AllegisSNOWUsers -snowFilter $snowfilter -snowOrg $snoworg -snowcred $snowcred -snowEnv $snoworg
    if ($snowusers -eq $null){write-host "no users fit $snowfilter. stopping"; break}
    $idnusers=get-AllegisIDNAccount -orgname $IDNorg -sourceid $IDNsourceid -IDNClientID $IDNClientID -IDNClientKey $IDNClientKey -accesstoken $IDNaccesstoken
    foreach ($idnuser in $idnusers){
        $idnuserdetail=get-AllegisIDNAccount -orgname $IDNorg -accountid $idnuser.id -IDNClientID $IDNClientID -IDNClientKey $IDNClientKey -accesstoken $IDNaccesstoken
        $idnuser | Add-Member -NotePropertyName 'detailed' -NotePropertyValue $idnuserdetail -Force
    }
    $compare=compare-object $idnusers.detailed.attributes $snowusers -Property sys_id -IncludeEqual
    foreach ($change in ($compare | sort -Property sideindicator -Descending)){
        switch ($change.sideindicator){
            '=>'{#new
                "adding $($change.sys_id) in IDN $IDNsourceid"
                new-AllegisIDNAccount -orgname $IDNorg -sourceid $IDNsourceid -IDNClientID $IDNClientID -IDNClientKey $IDNClientKey -accesstoken $IDNaccesstoken -newuser $snowusers.Where{$_.sys_id -eq $change.sys_id}[0]
            }
            '<='{#delete
                "removing $($change.sys_id) in IDN $IDNsourceid"
                remove-AllegisIDNAccount -orgname $IDNorg -IDNClientID $IDNClientID -IDNClientKey $IDNClientKey -accesstoken $IDNaccesstoken -accountid $idnusers.where{$_.detailed.attributes.sys_id -eq $change.sys_id}[0].id

            }
            '=='{#check for update
                $snowtemp=$snowusers.Where{$_.sys_id -eq $change.sys_id}[0]
                $idntemp=$idnusers.where{$_.detailed.attributes.sys_id -eq $change.sys_id}[0]
                if ([datetime]$snowtemp.sys_updated_on -ge [datetime]$idntemp.detailed.attributes.sys_updated_on)
                {
                    "updating $($change.sys_id) in IDN $IDNsourceid"
                    update-AllegisIDNAccount -orgname $IDNorg -IDNClientID $IDNClientID -IDNClientKey $IDNClientKey -sourceid $IDNsourceid -accesstoken $IDNaccesstoken -accountid $idntemp.id -userdetails $snowtemp
                    
                }                            
            }
        }
    }
    foreach ($id in $idnusers.where{$_.detailed.attributes.sys_id.length -ne 32}.id){
    remove-AllegisIDNAccount -orgname $IDNorg -IDNClientID $IDNClientID -IDNClientKey $IDNClientKey -accesstoken $IDNaccesstoken -accountid $id
    }
}