<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Indented! &#187; Stale Records</title>
	<atom:link href="http://www.indented.co.uk/index.php/tag/stale-records/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.indented.co.uk</link>
	<description></description>
	<lastBuildDate>Fri, 02 Jul 2010 10:45:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Microsoft DNS &amp; stale records</title>
		<link>http://www.indented.co.uk/index.php/2008/10/10/microsoft-dns-stale-records/</link>
		<comments>http://www.indented.co.uk/index.php/2008/10/10/microsoft-dns-stale-records/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 11:18:56 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Microsoft DNS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VbScript]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[reporting]]></category>
		<category><![CDATA[Stale Records]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[Windows 2003]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=199</guid>
		<description><![CDATA[This post explains how to identify and report on stale records in a dynamically updated Microsoft DNS zone. The time stamp taken from a DNS record represents the numbers of hours since 01/01/1601 00:00. The value can be converted into a useful date within a script. By default, all times are reported and tested in [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>This post explains how to identify and report on stale records in a dynamically updated Microsoft DNS zone.<br />
<span id="more-199"></span><br />
The time stamp taken from a DNS record represents the numbers of hours since 01/01/1601 00:00. The value can be converted into a useful date within a script. By default, all times are reported and tested in UTC.</p>
<p>A stale record is a record where both the No-Refresh Interval and Refresh Interval have passed without the time stamp updating. Ordinarily stale records would be removed by a Scavenging process. These scripts may be useful if trying to asses the impact of enabling Scavenging or reducing Aging intervals.</p>
<h3>Listing stale records with VbScript</h3>
<p>This script uses a WMI query to return all A records for a domain, then it sorts through each record, echoing when the time stamp is older than our pre-defined maximum age. The script will work best when run with cscript.</p>
<pre class="brush: vb;">
' No-Refresh + Refresh (in Days)
Const MAXIMUM_AGE = 4

' Connect to the MicrosoftDNS Namespace
Set objWMIService = _
  GetObject(&quot;winmgmts:\\dc01.internal.highorbit.co.uk\root\MicrosoftDNS&quot;)

' Query A records with MicrosoftDNS_AType class where the record is not static
Set colItems = objWMIService.ExecQuery(&quot;SELECT * FROM MicrosoftDNS_AType &quot; &amp;_
  &quot; WHERE ContainerName='internal.highorbit.co.uk' AND TimeStamp&lt;&gt;0&quot;)

For Each objItem In colItems
  ' Convert the timestamp into a date and time
  dtmTimeStamp = DateAdd(&quot;h&quot;, objItem.TimeStamp, &quot;01/01/1601 00:00:00&quot;)
  ' Compare the date and time with MAXIMUM_AGE
  If dtmTimeStamp &lt;= (Date() - MAXIMUM_AGE) Then
    ' Echo the record details if it is older than the MAXIMUM_AGE
    WScript.Echo objItem.OwnerName &amp; VbTab &amp; objItem.IPAddress &amp;_
      VbTab &amp; dtmTimeStamp
  End If
Next
</pre>
<h3>Listing stale records with PowerShell</h3>
<p>This snippet uses Get-WMIObject and a improved query to return only stale records rather than sorting after returning all dynamic records.</p>
<p>A timespan value is generated to represent the minimum value of TimeStamp for valid records.</p>
<pre class="brush: powershell;">
# No-Refresh + Refresh (in Days)
$TotalAgingInterval = 4

$ServerName = &quot;dc01.internal.highorbit.co.uk&quot;
$ContainerName = &quot;internal.highorbit.co.uk&quot;

$MinTimeStamp = [Int](New-TimeSpan `
  -Start $(Get-Date(&quot;01/01/1601 00:00&quot;)) `
  -End $((Get-Date).AddDays(-$TotalAgingInterval))).TotalHours

Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_AType&quot; `
  -Filter `
  &quot;ContainerName='$ContainerName' AND TimeStamp&lt;$MinTimeStamp AND TimeStamp&lt;&gt;0&quot; `
 | Select-Object OwnerName, `
  @{n=&quot;TimeStamp&quot;;e={(Get-Date(&quot;01/01/1601&quot;)).AddHours($_.TimeStamp)}}
</pre>
<h3>Reading Aging intervals with PowerShell</h3>
<p>The Aging intervals and the date the zone can be scavenged set on a zone can be read using WMI using the MicrosoftDNS_Zone class. As with the TimeStamp the .AddHours method must be used to return a date.</p>
<pre class="brush: powershell;">
$ServerName = &quot;dc01.internal.highorbit.co.uk&quot;
$ContainerName = &quot;internal.highorbit.co.uk&quot;

Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_Zone&quot; `
  -Filter &quot;ContainerName='$ContainerName'&quot; `
 | Select-Object NoRefreshInterval, RefreshInterval, `
  @{n=&quot;AvailForScavengeTime&quot;;e={
    (Get-Date(&quot;01/01/1601&quot;)).AddHours($_.AvailForScavengeTime)}}
</pre>
<h3>Localisation</h3>
<p>As mentioned at the beginning of this post, all times are reported in UTC by default. By calling a the ToLocalTime method the date returned can be converted to local time, using the time zone configured on the system executing the query.</p>
<pre class="brush: powershell;">
$ServerName = &quot;dc01.internal.highorbit.co.uk&quot;
$ContainerName = &quot;internal.highorbit.co.uk&quot;

$MinTimeStamp = [Int](New-TimeSpan `
  -Start $(Get-Date(&quot;01/01/1601 00:00&quot;)) `
  -End $((Get-Date).AddDays(-$TotalAgingInterval))).TotalHours

Get-WMIObject -Computer $ServerName `
  -Namespace &quot;root\MicrosoftDNS&quot; -Class &quot;MicrosoftDNS_AType&quot; `
  -Filter `
  &quot;ContainerName='$ContainerName' AND TimeStamp&lt;$MinTimeStamp AND TimeStamp&lt;&gt;0&quot; `
 | Select-Object OwnerName, `
  @{n=&quot;TimeStamp&quot;;e={
    ((Get-Date(&quot;01/01/1601&quot;)).AddHours($_.TimeStamp)).ToLocalTime()}}
</pre>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2008/10/10/microsoft-dns-stale-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
