---
title: "Active Directory Database: PowerShell Monitoring Made Easy"
description: "Learn to pinpoint the ntds.dit file and effectively monitor your Active Directory database with PowerShell, ensuring robust and streamlined network management."
canonical: "https://adamtheautomator.com/active-directory-database/"
---

# Active Directory Database: PowerShell Monitoring Made Easy

> Learn to pinpoint the ntds.dit file and effectively monitor your Active Directory database with PowerShell, ensuring robust and streamlined network management.

Source: https://adamtheautomator.com/active-directory-database/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Active Directory Database: PowerShell Monitoring Made Easy](https://adamtheautomator.com/wp-content/uploads/2019/08/database-152091_1280.png)

# Active Directory Database: PowerShell Monitoring Made Easy

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)30 January 20242 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Active Directory](/tag/active-directory/)[PowerShell](/tag/powershell/)

Table of Contents

*   [Ntds.dit (The Active Directory Database)](#h-ntds-dit-the-active-directory-database)
*   [Finding the AD Database with PowerShell](#h-finding-the-ad-database-with-powershell)
*   [Monitoring the Size of the AD Database](#h-monitoring-the-size-of-the-ad-database)

The Active Directory database is, by far, the most important piece of AD. After all, without the database, AD wouldn’t be much good at all. Where is the Active Directory database? Where is the ntds.dit location? And how to o you monitor the database? You’ll learn the answer to these questions in this tutorial!

It’s important to monitor all aspects of AD and the database itself is of utmost importance. This is why it’s well worth the time to investigate what the database consists of and how best to monitor it to ensure it stays healthy.

![Active Directory Database](https://adamtheautomator.com/wp-content/uploads/2024/01/active-directory-datacase-1024x576.jpg)

In this article, we’re going to build a PowerShell script that allows you to see a query each AD database on every DC in your domain and determine one important metric about the database; the overall database size.

## Ntds.dit (The Active Directory Database)

An AD database consists of a file called _[ntds.dit](https://www.ultimatewindowssecurity.com/blog/default.aspx?d=10/2017)_ and the ntds.dit location is usually in _C:\\Windows\\NTDS_ of every domain controller.

To ensure we get the proper path, we’ll first need to figure out where the database path is. This value is stored in the registry key _HKLM:\\System\\CurrentControlSet\\Services\\NTDS\\Parameters_.

## Finding the AD Database with PowerShell

Let’s query all of the DCs in our environment for the database file path.

```powershell
$dcs = (Get-ADDomainController).Name
$dbs = Invoke-Command -ComputerName $dcs -ScriptBlock {
    Get-ItemProperty -Path HKLM:\System\CurrentControlSet\Services\NTDS\Parameters
} | Select PSComputerName,'DSA Database File'
```

Now that I know the path to the Active Directory database on each DC, I can now query each one of the current sizes. To do this, I’ll use a _[foreach](https://adamtheautomator.com/powershell-foreach/ "foreach")_ loop and iterate through the `$dbs` variable I created above which contains the domain controller name and the path to the database file on each.

## Monitoring the Size of the AD Database

To more easily understand the output, I’m going to use an `$output` hashtable, assign values to it as I’m reading each database file like the domain controller name and the size of each database. I’ll then convert this to a custom object when I’m done reading the database file. This will show a nicer output than simply _PSComputerName_, _DSA Database File_ and the size.

```powershell
$dbs | foreach {
    $output = @{}
    $path = $_.'DSA Database File'
    $output.Add('DomainController', $_.PSComputerName)
    $size = Invoke-Command -ComputerName $_.PSComputerName -ScriptBlock {
        (Get-ItemProperty -Path $using:path).Length /1GB
    }
    $output.Add('DatabaseSizeDB', $size)
    [pscustomobject]$output
}
```

This snippet will give you a nice output of `DatabaseSizeDB` and a `DomainController` property. In my demo environment, I only have a single DC. If you were running this in production, you’d see each of your domain controllers  
along with the total database size in GB next to each one.

Now you have a script you can run at any time to get a point-in-time snapshot of just how big each of your [Active Directory](https://adamtheautomator.com/active-directory-auditing/) database files has grown to!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Factive-directory-database%2F&text=Active%20Directory%20Database%3A%20PowerShell%20Monitoring%20Made%20Easy)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Factive-directory-database%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Factive-directory-database%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2024/11/image-23.png)

### [Managing Active Directory Groups with PowerShell: The Ultimate Guide](/powershell-ad-groups-guide/)

Learn how to manage Active Directory groups with PowerShell! This hands-on guide shows you how to query, create and modify AD groups using practical real-world

![](https://adamtheautomator.com/wp-content/uploads/2019/07/panic-1393619_1280.png)

### [How to Find Locked Out Users in Active Directory with PowerShell](/find-locked-out-users-in-active-directory-powershell/)

See what we can do to find locked out users in Active Directory with PowerShell!

![](https://adamtheautomator.com/wp-content/uploads/2019/08/darknet-3588402_1280.jpg)

### [Master your LDAP Filters in PowerShell while Learning AD](/ldap-filter/)

Learning how to use LDAP filter, how to filter with the Active Directory PowerShell cmdlets, and learn the right way to filter AD objects.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
