ADDatabase and Log File Free Space

PC Repair Tools

Advanced Registry Cleaner PC Diagnosis and Repair

Get Instant Access

Every Active Directory database needs free disk space to grow. The AD transaction log files also need free space. This script monitors the amount of available disk space on the drives holding the AD database and log files and raises an alert if the available disk space drops below a given amount.

The script begins by retrieving a list of domain controllers from a DomainClass object. The location of the AD database and log files may be different on each domain controller. An advantage of the Microsoft Operations Manager is that it installs a COM helper object known as the OOMADs, which can be used to make several system calls not available through regular VBScript objects.

For our script to locate these files, we must read some values from the registry of the domain controller. We can do this by using an instance of the RegistryClass class described in the previous section. We can find the location of the AD database and log files in the following registry key:

HKLM\System\CurrentControlSet\Services\NTDS\Parameters

The database location is stored in the value DSA Database f i l e and the log file location is stored in the value Database log files path. The script is interested in only the drive letter rather than the full path. The WMIClass object's GetAvailableSpace method is called and the server and drive letter are passed as arguments. This method executes a WMI query on the server and returns the amount of available space in bytes. Because most people are accustomed to reading drive-space values in gigabytes rather than bytes, the number is converted into a gigabyte format.

The minimum amount of free drive space is set by the DBThreshold constant for the AD database and by the LogThreshold constant for the log files. It is important to note here that the value used for each of these constants depends on how we chose to display the value of available space. The script currently displays the value in gigabytes, so the DBThreshold value of 1 means 1 GB. If we decide to lower the threshold to 500 MB we must change two items in the code. The first is the value in the DBThreshold constant itself. The second is the following code:

DBFreeSpace = FormatNumber _

(WMI.GetAvailableSpace(Server,DBDrive) / GB)

The constant GB refers to the number of bytes in a single gigabyte. Constants are also defined in the script for megabytes (MB) and kilobytes (KB). We simply need to substitute MB for GB in the script.

You can follow a similar procedure to change the log-files threshold. The value of the LogThreshold constant and the line of code setting the LogFreeSpace variable would be changed, as described earlier.

<comment>

Microsoft SCOM runs a script similar to this every 15 minutes in response to an event rule.

Schedule to your own liking.

<script language="VBScript" src="..\includes\RegistryClass.vbs" />

<script 1anguage="VBScript" src="..\inc1udes\DomainC1ass.vbs" /> <script 1anguage="VBScript" src="..\inc1udes\WMIC1ass.vbs" /> <script 1anguage="VBScript" src="..\inc1udes\OutputC1ass.vbs" /> <script> Option Explicit

' Adjust thresholds to your minimum DB and Log free space. ' It currently uses Gigabytes as the unit of measure. Const DBThreshold = 1 Const LogThreshold = 1

' Registry keys pointing to the AD Database and log file locations.

Const ADKey = "HKLM\System\CurrentContro1Set\Services\NTDS\Parameters"

Const DBValue = "DSA Database file"

Const LogValue = "Database log files path"

' Number of bytes in a kilobyte, megabyte, and gigabyte.

Const KB = 1024

Const MB = 1048576

Const GB = 1073741824

Dim Registry

Set Registry = New RegistryClass Dim Domain

Set Domain = New DomainClass Dim Output

Set Output = New OutputClass Dim WMI

Set WMI = New WMIClass Dim Servers, Server

Set Servers = Domain.GetDomainControllers For Each Server In Servers Dim DBDrive, LogDrive Dim DBFreeSpace, LogFreeSpace Registry.Server = Server Registry.Connect DBDrive = Left _

(Registry.GetVa1ue(ADKey,DBVa1ue,Registry.REG_SZ),2) LogDrive = Left _

(Registry.GetVa1ue(ADKey,LogVa1ue,Registry.REG_SZ),2) DBFreeSpace = FormatNumber _

(WMI.GetAvai1ab1eSpace(Server,DBDrive) / GB) If DBDrive = LogDrive Then

LogFreeSpace = DBFreeSpace Else

LogFreeSpace = FormatNumber _

(WMI.GetAvai1ab1eSpace(Server,LogDrive) / GB)

End If

Output.Display Server

Output.Display "DBDrive = " & DBFreeSpace Output.Display "LogDrive = " & LogFreeSpace If DBFreeSpace < DBThreshold Then Output.ModalAlert _

Server & " is low on DB space (" & DBFreeSpace & ")"

End If

If LogFreeSpace < LogThreshold Then Output.ModalAlert _

Server & " is low on log space (" & LogFreeSpace & ")"

End If Next

Was this article helpful?

0 0
Computer Hard Drive Data Recovery

Computer Hard Drive Data Recovery

Learn How To Recover Your Hard Drive Data After A Computer Failure.

Get My Free Ebook


Post a comment