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 DHCP
Windows DHCP
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.DHCP: Dynamic Host Configuration Protocol (DHCP). A communications protocol that lets network administrators manage centrally and automate the assignment of Internet Protocol (IP) addresses in an organization's network.
1,023 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
{count} votes

Accepted answer
  1. Dave Patrick 426.1K Reputation points MVP
    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--

    1 person found this answer helpful.

5 additional answers

Sort by: Newest
  1. John JY 221 Reputation points
    2021-01-29T21:15:33.933+00:00

    I tried on a domain controller and it worked like a charm. the bios name is listed in computer.txt file.

    Thank you for your great help!


  2. Dave Patrick 426.1K Reputation points MVP
    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--

    0 comments No comments

  3. 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!


  4. Dave Patrick 426.1K Reputation points MVP
    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--

    0 comments No comments