I have a script which among other things, updates a CName record in DNS. It updates the same record on multiple DNS servers, one at each site as we can't wait for replication.
The first time the Get-DnsServerResourceRecord command runs, it takes over 5 minutes to get a result, but then only takes 12 seconds every other time.
Can anyone think of a reason why it is so slow? This is all on the same site, and isn't using any slow links. The script is below, along with the timed results.
EDIT: Forgot to mention that this script runs as a scheduled task using a service account. The delay only happens when the scheduled task runs - it doesn't happen if I run it myself.
Measure-Command { $NewObj = Get-DnsServerResourceRecord -ComputerName "<domainController>" -Name "mft" -ZoneName "<domainFQDN>" -RRType CName } Measure-Command { $OldObj = Get-DnsServerResourceRecord -ComputerName "<domainController>" -Name "mft" -ZoneName "<domainFQDN>" -RRType CName } Measure-Command { $NewObj.RecordData.HostNameAlias = "<newHost>.<domainFQDN>" Set-DnsServerResourceRecord -NewInputObject $NewObj -OldInputObject $OldObj -ComputerName "<domainController>" -ZoneName "<domainFQDN>" -PassThru } The results:
Days : 0 Hours : 0 Minutes : 5 Seconds : 7 Milliseconds : 948 Ticks : 3079486397 TotalDays : 0.00356422036689815 TotalHours : 0.0855412888055555 TotalMinutes : 5.13247732833333 TotalSeconds : 307.9486397 TotalMilliseconds : 307948.6397 Days : 0 Hours : 0 Minutes : 0 Seconds : 12 Milliseconds : 425 Ticks : 124256457 TotalDays : 0.00014381534375 TotalHours : 0.00345156825 TotalMinutes : 0.207094095 TotalSeconds : 12.4256457 TotalMilliseconds : 12425.6457 Days : 0 Hours : 0 Minutes : 0 Seconds : 13 Milliseconds : 468 Ticks : 134686180 TotalDays : 0.000155886782407407 TotalHours : 0.00374128277777778 TotalMinutes : 0.224476966666667 TotalSeconds : 13.468618 TotalMilliseconds : 13468.618 EDIT2: Right so I tried Measure-Command {Import-Module DNSServer} and basically it just sits there for hours doing nothing. I have noticed however that the script generally appears to run slow anyway so I did this:
Measure-Command{ Start-Sleep -s 1 } Result:
Days : 0 Hours : 0 Minutes : 0 Seconds : 2 Milliseconds : 139 Ticks : 21393401 TotalDays : 2.4760880787037E-05 TotalHours : 0.000594261138888889 TotalMinutes : 0.0356556683333333 TotalSeconds : 2.1393401 TotalMilliseconds : 2139.3401 So maybe its the script just running generally slow? I have tried exporting the task, bumping the priority to 0 and the result is the same. I've tried letting it run as SYSTEM and my account, and the result is the same. I have even tried creating a new script with nothing more than the Measure-Command and Start-Sleep command, and it doesn't appear to do anything (no output).
Any thoughts as to what we could do next? I've updated the name of the question also, to better reflect the issue.
Thanks for the help
DnsServerloaded before you run the cmdlet? I could imagine loading the module could take some time, but 5 minutes is too long for that too.Measure-Command { import-module dnsserver }in front of the first invocation and see what it reports.