Skip to content

Azure Directory

Microsoft Entra ID users, groups and devices

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/azure-directory/index.md to help me query Azure Directory with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Count managed devices by operating system

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT operating_system, count(*)
FROM azure.main.directory_devices_delta()
WHERE _row_kind IS NULL
GROUP BY operating_system

Quick start

Choose where to run Azure Directory, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-azure-directory'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

azure_graph credentials

Microsoft Entra app-only (client-credentials) credentials for Microsoft Graph

Get these credentials →
secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT operating_system, count(*)
FROM azure.main.directory_devices_delta()
WHERE _row_kind IS NULL
GROUP BY operating_system
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Microsoft Entra directory (users/groups/devices) via Graph delta — vgi-azure-directory

Catalog

Everything azure exposes once attached — read straight from the worker's released build.

azure 1 schema
main 1 view · 3 functions

Microsoft Entra ID directory objects (users, groups, devices) as incremental Graph delta feeds.

Schema examples (3)
Examples (3)

Full sync of enabled users

SELECT id, user_principal_name, display_name
FROM azure.main.directory_users_delta()
WHERE _row_kind IS NULL AND account_enabled;

Incremental sync from a saved cursor

SELECT id, change_type, display_name
FROM azure.main.directory_users_delta(delta_token := '<@odata.deltaLink>');

Security-enabled groups

SELECT id, display_name, mail
FROM azure.main.directory_groups_delta()
WHERE _row_kind IS NULL AND security_enabled;
Views
directory_collections 2 examples4 cols

The directory collections this catalog exposes (users, groups, devices) and the delta table function that serves each. Browsable without credentials.

Columns
collection VARCHAR
The collection slug (users / groups / devices).
object_type VARCHAR
The singular Microsoft Entra object type the collection contains.
table_function VARCHAR
The catalog table function that syncs this collection as a delta feed.
description VARCHAR
A one-line description of the collection.
Examples (2)

List every collection and the table function that serves it

SELECT collection, table_function
FROM azure.main.directory_collections
ORDER BY collection;

Find the table function for a given object type

SELECT table_function
FROM azure.main.directory_collections
WHERE object_type = 'group';
Link
Table functions
directory_devices_delta (delta_token := VARCHAR, select_fields := VARCHAR) 3 examples

Entra ID devices via Microsoft Graph delta.

Named arguments
delta_token := VARCHAR
A previously persisted `@odata.deltaLink` (the `_delta_next` value from a prior scan's marker row), replayed verbatim to return only what changed since. Empty (the default) performs a full sync. · default ""
select_fields := VARCHAR
Comma-separated Microsoft Graph `$select` projection of fields to fetch. Pinned for the life of a delta token — changing it forces a full resync. Defaults to this collection's standard columns. · default "id,displayName,operatingSystem,accountEnabled"
Returns columns
id VARCHAR
The directory object's id (GUID). NULL on the marker row.
change_type VARCHAR
'upsert' (created/updated) or 'removed' (deleted). NULL on the marker row.
removed_reason VARCHAR
For removed rows, the @removed.reason ('changed' or 'deleted'); NULL otherwise.
display_name VARCHAR
The device's display name.
operating_system VARCHAR
The device's operating system (e.g. Windows, iOS).
account_enabled BOOLEAN
Whether the device account is enabled.
_row_kind VARCHAR
NULL for data rows; 'marker' for the single trailing cursor row.
_delta_next VARCHAR
On the marker row, the verbatim @odata.deltaLink to persist and replay as the next cursor; NULL on data rows.
Examples (3)

Full sync of all devices (data rows only)

SELECT id, display_name, operating_system, account_enabled
FROM azure.main.directory_devices_delta()
WHERE _row_kind IS NULL;

Device count by operating system

SELECT operating_system, count(*)
FROM azure.main.directory_devices_delta()
WHERE _row_kind IS NULL
GROUP BY operating_system;

Read the delta cursor to persist for the next sync

SELECT _delta_next
FROM azure.main.directory_devices_delta()
WHERE _row_kind = 'marker';
Link
directory_groups_delta (delta_token := VARCHAR, select_fields := VARCHAR) 3 examples

Entra ID groups via Microsoft Graph delta.

Named arguments
delta_token := VARCHAR
A previously persisted `@odata.deltaLink` (the `_delta_next` value from a prior scan's marker row), replayed verbatim to return only what changed since. Empty (the default) performs a full sync. · default ""
select_fields := VARCHAR
Comma-separated Microsoft Graph `$select` projection of fields to fetch. Pinned for the life of a delta token — changing it forces a full resync. Defaults to this collection's standard columns. · default "id,displayName,mail,securityEnabled"
Returns columns
id VARCHAR
The directory object's id (GUID). NULL on the marker row.
change_type VARCHAR
'upsert' (created/updated) or 'removed' (deleted). NULL on the marker row.
removed_reason VARCHAR
For removed rows, the @removed.reason ('changed' or 'deleted'); NULL otherwise.
display_name VARCHAR
The group's display name.
mail VARCHAR
The group's mail address, if mail-enabled.
security_enabled BOOLEAN
Whether the group is a security group.
_row_kind VARCHAR
NULL for data rows; 'marker' for the single trailing cursor row.
_delta_next VARCHAR
On the marker row, the verbatim @odata.deltaLink to persist and replay as the next cursor; NULL on data rows.
Examples (3)

Full sync of all groups (data rows only)

SELECT id, display_name, mail, security_enabled
FROM azure.main.directory_groups_delta()
WHERE _row_kind IS NULL;

Security-enabled groups only

SELECT id, display_name
FROM azure.main.directory_groups_delta()
WHERE _row_kind IS NULL AND security_enabled;

Read the delta cursor to persist for the next sync

SELECT _delta_next
FROM azure.main.directory_groups_delta()
WHERE _row_kind = 'marker';
Link
directory_users_delta (delta_token := VARCHAR, select_fields := VARCHAR) 3 examples

Entra ID users via Microsoft Graph delta (incremental change feed with removals).

Named arguments
delta_token := VARCHAR
A previously persisted `@odata.deltaLink` (the `_delta_next` value from a prior scan's marker row), replayed verbatim to return only what changed since. Empty (the default) performs a full sync. · default ""
select_fields := VARCHAR
Comma-separated Microsoft Graph `$select` projection of fields to fetch. Pinned for the life of a delta token — changing it forces a full resync. Defaults to this collection's standard columns. · default "id,userPrincipalName,displayName,accountEnabled"
Returns columns
id VARCHAR
The directory object's id (GUID). NULL on the marker row.
change_type VARCHAR
'upsert' (created/updated) or 'removed' (deleted). NULL on the marker row.
removed_reason VARCHAR
For removed rows, the @removed.reason ('changed' or 'deleted'); NULL otherwise.
user_principal_name VARCHAR
The user's UPN (sign-in name).
display_name VARCHAR
The user's display name.
account_enabled BOOLEAN
Whether the account is enabled for sign-in.
_row_kind VARCHAR
NULL for data rows; 'marker' for the single trailing cursor row.
_delta_next VARCHAR
On the marker row, the verbatim @odata.deltaLink to persist and replay as the next cursor; NULL on data rows.
Examples (3)

Full sync of all users (data rows only)

SELECT id, user_principal_name, display_name, account_enabled
FROM azure.main.directory_users_delta()
WHERE _row_kind IS NULL;

Incremental sync replaying a previously saved delta cursor

SELECT id, change_type, display_name
FROM azure.main.directory_users_delta(delta_token := '<@odata.deltaLink>');

Read the delta cursor to persist for the next sync

SELECT _delta_next
FROM azure.main.directory_users_delta()
WHERE _row_kind = 'marker';
Link

Credentials

The secret type azure declares, as reported by the worker itself.

azure_graph

How to get these credentials

Microsoft Entra app-only (client-credentials) credentials for Microsoft Graph

secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Key Type Required Description
tenant_id VARCHAR — Directory (tenant) ID from the app registration's Overview page in Microsoft Entra ID
client_id VARCHAR — Application (client) ID from the app registration's Overview page
client_secret secret VARCHAR — Client secret value created under the app registration's Certificates & secrets page

The worker doesn't mark which keys are required.

Needed by directory_users_deltadirectory_groups_deltadirectory_devices_delta

Create the secret in the same session, after attaching azure — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

users_bind_probe — Bind directory_users_delta and expose its result columns (credential-free; drop LIMIT 0 and attach an azure_graph secret to sync real users)

SELECT id, user_principal_name, display_name, account_enabled
FROM azure.main.directory_users_delta()
LIMIT 0;

Uses directory_users_delta

groups_bind_probe — Bind directory_groups_delta and expose its result columns (credential-free; attach an azure_graph secret to sync real groups)

SELECT id, display_name, mail, security_enabled
FROM azure.main.directory_groups_delta()
LIMIT 0;

Uses directory_groups_delta

devices_bind_probe — Bind directory_devices_delta and expose its result columns (credential-free; attach an azure_graph secret to sync real devices)

SELECT id, display_name, operating_system, account_enabled
FROM azure.main.directory_devices_delta()
LIMIT 0;

Uses directory_devices_delta

Full sync of enabled users

SELECT id, user_principal_name, display_name
FROM azure.main.directory_users_delta()
WHERE _row_kind IS NULL AND account_enabled

Uses directory_users_delta

Incremental sync from a saved cursor

SELECT id, change_type, display_name
FROM azure.main.directory_users_delta(delta_token := '<@odata.deltaLink>')

Uses directory_users_delta

List every collection and the table function that serves it

SELECT collection, table_function
FROM azure.main.directory_collections
ORDER BY collection

Uses directory_collections

9 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • List the enabled users in the Entra ID tenant with their user principal name and display name.
  • After syncing users, how do I get the cursor to use for the next incremental sync?
  • Which groups in the directory are security-enabled?
  • How many registered devices are there of each operating system?
  • What directory object types can I sync, and which table function serves each?

Azure Directory is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.