Share via

help on powershell script

John JY 221 Reputation points
2021-01-15T22:02:46.79+00:00

Hi,

We need to change around 2000 member servers dynamic DNS A records to static. I have it in csv or text format.
Can anyone share how to script to change them?

Thank you.

Windows for business | Windows Client for IT Pros | Networking | Network connectivity and file sharing
Windows for business | Windows Server | User experience | PowerShell

Answer accepted by question author

Anonymous
2021-01-15T22:54:02.273+00:00

This PowerShell should sort it.

foreach ($server in (Get-Content c:\Computers.txt)) {

$OldObj = Get-DnsServerResourceRecord -Name $server -ZoneName "mydomain.local.com" -RRType "A"
$NewObj = $OldObj.Clone()
$NewObj.TimeToLive = [System.TimeSpan]::FromHours(0)
Set-DnsServerResourceRecord -NewInputObject $NewObj -OldInputObject $OldObj -ZoneName "mydomain.local.com" -PassThru

}

--please don't forget to Accept as answer if the reply is helpful--

Was this answer helpful?

1 person found this answer helpful.

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2021-01-29T19:23:28.36+00:00

    Do I need to run the script on a domain controller?

    I think that's how I did my testing but it was quite a while ago.

    --please don't forget to Accept as answer if the reply is helpful--

    Was this answer helpful?

    0 comments No comments

  2. John JY 221 Reputation points
    2021-01-29T19:20:24.757+00:00

    Thanks for your quick response and help.

    I did check Get-Content c:\tmp\Computers.txt and got the computers names
    changed the computer name in txt file to bios name with no mydomain.local.com

    still same errors and let me know what else I can try? Do I need to run the script on a domain controller?

    Thank you again!

    Was this answer helpful?


  3. Anonymous
    2021-01-29T18:36:37.483+00:00

    Sounds like the record for that $server did not exist.

    --please don't forget to Accept as answer if the reply is helpful--

    Was this answer helpful?

    0 comments No comments

  4. John JY 221 Reputation points
    2021-01-29T18:02:22.647+00:00

    Sorry for the reply and did not get a chance

    Here is error I got when I ran the script. (I did replace mydomain.local.com with my zone name)

    Get-DnsServerResourceRecord : Failed to get the zone information for mydomain.local.com on server server1.
    At line:2 char:12

    • $OldObj = Get-DnsServerResourceRecord -Name $server -ZoneName "mydomain ...
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (mydomain.local.com:root/Microsoft/...rResourceRecord) [Get-DnsServerResourceRec
      ord], CimException
    • FullyQualifiedErrorId : WIN32 1722,Get-DnsServerResourceRecord

    You cannot call a method on a null-valued expression.
    At line:3 char:2

    • $NewObj = $OldObj.Clone()
    • ~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

    The property 'TimeToLive' cannot be found on this object. Verify that the property exists and can be set.
    At line:4 char:2

    • $NewObj.TimeToLive = [System.TimeSpan]::FromHours(0)
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : PropertyNotFound

    Set-DnsServerResourceRecord : Cannot validate argument on parameter 'NewInputObject'. The argument is null or empty.
    Provide an argument that is not null or empty, and then try the command again.
    At line:5 char:46

    • Set-DnsServerResourceRecord -NewInputObject $NewObj -OldInputObject ...
    • ~~~~~~~
    • CategoryInfo : InvalidData: (:) [Set-DnsServerResourceRecord], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,Set-DnsServerResourceRecord

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.