F# type providers for querying Active Directory

Active Directory remains central to many Australian organisations, often as an on-premises AD DS forest joined to Microsoft Entra ID. A type provider can expose strongly typed F# values over data reached through LDAP or Microsoft Graph. Attribute names and result shapes become visible to the compiler, while routine administration keeps familiar functional operations.

This matters when an operations script must distinguish a disabled account from one missing an optional department, or when a group report needs a guaranteed property name. It reduces the string-heavy mistakes that can turn a routine user audit into an incident. Users, groups, computers and organisational units can become first-class F# values rather than loosely structured records.

Australian deployments add practical context. Teams and SharePoint are routine workplace tools, while hybrid directory estates remain common across Sydney, Melbourne, Brisbane and Canberra. Administrators often work between an office network and a home connection, so scripts need bounded retries, predictable output and useful logging rather than relying on an interactive domain session.

A type provider supplies types and structure; it does not turn Active Directory into a conventional database. Results remain live directory data, permissions still apply, and the underlying protocol changes between AD DS and Entra ID. Keeping that boundary clear makes F# directory automation safer to maintain.

A typed view of directory data

Directory data is easy to misuse because many tools represent every attribute as a string. A typed provider can distinguish a required account name from an optional title, and expose a multi-valued attribute as a sequence rather than an ambiguous comma-separated value. Filters then read like ordinary F# code instead of manually assembled LDAP strings.

The compiler can also identify misspelled properties before a script reaches production. That does not make Active Directory rigid: its schema is extensible, and attributes may be absent or have different value types across environments. A robust provider should model uncertainty explicitly, using optional values for nullable properties and dedicated representations for distinguished names, timestamps and binary data.

Designing a practical provider boundary

A custom F# provider normally derives from TypeProvider, with TypeProviderConfig supplying configuration and ProvidedTypeContext generating the exposed types. The provider can define User, Group, Computer and organisational-unit records with named properties, constructors and query methods. Those generated types become part of the consuming project’s compile-time environment.

It is better to generate a stable contract than to discover an entire production directory during compilation. Runtime operations can use System.DirectoryServices.Protocols for AD DS and Microsoft Graph for Entra ID, with the provider translating calls into the appropriate protocol. An illustrative client might look like this:

let engineering =
    directory.Users
        .Where(fun user -> user.Department = Some "Engineering")
        .OrderBy(fun user -> user.SamAccountName)

LDAP and Graph must not be presented as interchangeable. Graph exposes cloud-directory semantics, permissions and pagination that differ from an on-premises directory, so a useful API should identify the source of each result rather than hiding it behind ambiguous methods.

Filtering at the directory server

Directory queries should run server-side whenever possible. An LDAP provider should construct SearchRequest objects, escape filter values according to the relevant LDAP filtering rules, and request pages of results instead of retrieving an entire organisational unit. Without those controls, a report intended for 50 accounts could accidentally pull tens of thousands from a busy domain.

If the generated types implement IQueryable, F# query expressions can translate into that server-side operation. If they do not, the provider should expose explicit filter methods with the same behaviour. Either way, the escape function belongs inside the provider; callers should never interpolate raw account names or group strings into LDAP filters.

Graph queries need different treatment. They use their own filtering syntax, consistency model, throttling limits and cursor-based pagination. Group reporting also needs deliberate handling of direct membership, nested groups, primary groups and token-group membership, since treating memberOf as a flat list can produce duplicates or omit transitive membership.

Protecting credentials and directory access

A read-only bind account should be sufficient for most reporting and automation. It should have access only to the required organisational units and attributes, be protected by a strong managed password, and never be a member of Domain Admins. For Graph access, scoped application permissions and managed identities can avoid storing a user password altogether, while an AD DS service account may be protected as a group managed service account.

Secrets passed at runtime should come from an approved vault or secret store rather than F# source, generated provider code or compiler configuration. AD DS connections should use TLS and LDAP signing where supported. Personal administration on mobile devices also needs sound credential hygiene; Zack Michaels’ iPhone Keychain guide shows how iPhone users can generate and retain strong passwords, although enterprise directory credentials still belong in a managed enterprise vault.

Access to sensitive attributes should be logged and reviewed just like any other privileged operation. The script should record the identity it used, the directory source, the query scope and the number of returned records without writing passwords or full directory objects into ordinary application logs.

Running hybrid identity across Australia

A hybrid provider needs explicit rules for synchronised objects. During Microsoft Entra Connect synchronisation, attributes may be overwritten, cloud-only objects may exist, and the same person may appear in several sources. The provider should therefore expose the source and object identifiers, allowing operators to reconcile reports instead of assuming both directories contain identical facts.

For Australian organisations subject to the federal Privacy Act 1988, directory automation that touches personal information should support the Australian Privacy Principles, particularly security and access controls. Access logs, least-privilege roles and auditable change processes provide useful evidence, while the Notifiable Data Breaches scheme makes timely investigation of exposed credentials more important.

State regimes can add further obligations. The New South Wales Privacy and Personal Information Protection Act 1998 and Victoria’s Health Records Act 2001, among others, may apply to particular records even where the application also operates under federal privacy law. The Australian Signals Directorate’s Australian Cyber Security Centre publishes the Essential Eight, which provides a practical baseline for identity controls, patching, backups and incident preparation.

Moving from prototype to operations

A provider should begin against a disposable AD DS test forest and a mocked Graph boundary. Contract tests can verify paging, escaping, malformed records, throttling and permission failures without risking production identities. The same suite can run against representative data in CI, catching changes in generated types before a scheduled audit reaches an organisation’s real directory.

Package the provider as a versioned library, then expose small command-line tools for specific jobs such as stale-account reports, group membership exports and service-account reviews. Those tools should emit structured JSON or CSV, return meaningful exit codes, record query duration and handle transient failures with bounded retries. Publishing compiled executables also avoids requiring every operator to install the F# compiler.

The result is more than a tidier script. Directory access gains a documented contract, testable behaviour and consistent operational controls. Teams can review the provider like other infrastructure code, reproduce results from recorded inputs and adapt workflows as AD DS and Entra ID responsibilities change.

For organisations ready to replace brittle scripts with a tested hybrid identity tool, contact Karl to discuss provider design, Graph integration and a staged rollout.

Experience

Information Technology Consulting

Independent Practice

Provides IT consulting services focused on infrastructure planning, cloud migration strategy, and systems architecture. Engagements draw on years of hands-on sysadmin and development experience across Linux, Windows, and hybrid environments.

K9 Search & Rescue Volunteer

Ongoing

Active participant in K9 Search & Rescue operations, combining technical logistics skills with field support for canine search teams.

Karl Katzke's Blog

October 2006 – May 2014

Published a long-running personal technology blog covering cloud vs. in-house infrastructure, F# and Mono on OSX, hardware vendor critiques, RAID card performance analysis, and sysadmin storytelling. Notable posts include "When Sysadmins Ruled the Earth" (May 15, 2014) and "Getting Started with F# and Mono on OSX" (December 22, 2012).

Credentials

A small badge icon with a shield shape in muted blue tones on a light background

Systems Administration

Deep experience with Linux (RHEL, SLES, CentOS), high-availability clusters, and STONITH configurations.

A small badge icon with a gear shape in muted blue tones on a light background

Cloud Infrastructure

Practical knowledge of AWS EC2, reserved instances, and cost analysis for cloud vs. on-premises deployments.

A small badge icon with a code symbol in muted blue tones on a light background

Development

Proficient in F#, PHP (Symfony), and cross-platform tooling including Mono and MonoDevelop on OSX.

Studies

F# & Functional Programming

Self-directed, 2012

Explored strongly typed functional programming with F# on OSX using the Mono runtime. Published a detailed getting-started guide covering toolchain setup and cross-platform game development research.

High-Availability & Cluster Management

Professional Development, 2009

Configured and documented crm_mon email alerting for STONITH events on SLES11-HAE clusters, integrating with Nagios monitoring for production environments.

Hardware & Storage Performance

Ongoing

Conducted hands-on benchmarking of SATA/SAS RAID controllers including HighPoint RocketRaid 2740 and LSI/SuperMicro AOC-USASLP2-H8iR, comparing against software RAID configurations.

Skills

A small icon representing a server with clean geometric lines in slate blue

Linux Administration

RHEL, SLES, CentOS — package management, kernel tuning, HA clustering, and monitoring integration.

A small icon representing a cloud shape with clean geometric lines in slate blue

Cloud Architecture

AWS EC2, reserved-instance planning, cost modeling, and hybrid infrastructure strategy.

A small icon representing code brackets with clean geometric lines in slate blue

F# & .NET/Mono

Functional programming on OSX, MonoDevelop toolchain, and cross-platform game-dev exploration.

A small icon representing a database cylinder with clean geometric lines in slate blue

PHP & Symfony

Web application development with the Symfony framework and the broader PHP ecosystem.

A small icon representing a storage drive with clean geometric lines in slate blue

Storage & RAID

SATA/SAS controller evaluation, md RAID configuration, and performance benchmarking.

A small icon representing a shield with clean geometric lines in slate blue

High Availability

Pacemaker, STONITH, crm_mon alerting, and Nagios integration for production cluster monitoring.