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.

    $NewObj = Get-DnsServerResourceRecord -ComputerName "<domainController>" -Name "mft" -ZoneName "<domainFQDN>" -RRType CName
    $OldObj = Get-DnsServerResourceRecord -ComputerName "<domainController>" -Name "mft" -ZoneName "<domainFQDN>" -RRType CName
    $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:

    Start-Sleep -s 1


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

  • Is the module DnsServer loaded before you run the cmdlet? I could imagine loading the module could take some time, but 5 minutes is too long for that too. – Gerald Schneider Feb 2 '17 at 14:27
  • As this runs as a scheduled task (forgot to mention sorry), that probably is the case. When I run it, it takes just over a second to run the first command, then a fraction of a second for the rest. – Stuart475898 Feb 2 '17 at 14:38
  • Could still be the module loading. Place Measure-Command { import-module dnsserver } in front of the first invocation and see what it reports. – Gerald Schneider Feb 2 '17 at 14:41
  • Update added under EDIT2 in question – Stuart475898 Feb 3 '17 at 9:54

Ok now I am confused. Was about to raise a support case with Microsoft and removed all of the measure-command commands, and it runs absolutely fine. No issues at all. Feeling pretty deflated now...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.