Public/new-AllegisIDNAccount.ps1

function new-AllegisIDNAccount ($orgname, $sourceid, $IDNClientID, $IDNClientKey, $accesstoken, $newuser){
    if (!!$IDNClientID -and !!$IDNClientKey){
        $header = get-AllegisIDNBasicAuthHeader -IDNClientID $IDNClientID -IDNClientKey $IDNClientKey
    }elseif(!!$accesstoken){
        $header=get-AllegisIDNprivateHeader $accessToken
    }
    $schema=get-AllegisIDNsourceSchema -orgName $orgname -sourceid $sourceid -accessToken $accesstoken
    $account=@()
    foreach($attr in $schema[0].fields.name)
    {
        if ($account.count -eq 0){
            $account=[pscustomobject]@{"$attr"="$($newuser.$attr)"}
        }else{
            $account | Add-Member -NotePropertyName "$attr" -NotePropertyValue "$($newuser.$attr)"
        }
    }
    if (!$header){Write-Warning 'unable to create an auth header with provided parameters';return $null}
    $url="https://$orgname.api.identitynow.com/v2/accounts?sourceId=$sourceid&org=$orgname"
    $body=$account | ConvertTo-Json -Depth 10
    $response=Invoke-WebRequest -UseBasicParsing -Uri $url -Headers $header -Method Post -Body $body
    $account=$response.Content | ConvertFrom-Json
    return $account
}