question

JohnJY-4666 avatar image
0 Votes"
JohnJY-4666 asked ·

anyone can help to turn dynamic DNS server records to static DNS server records?

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-server-powershellwindows-dhcp-dns
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Just checking in to see if the information provided was helpful.
Please let us know if you would like further assistance.

0 Votes 0 ·
DSPatrick avatar image
0 Votes"
DSPatrick answered ·

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--









·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnJY-4666 avatar image
0 Votes"
JohnJY-4666 answered ·

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



·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DSPatrick avatar image
0 Votes"
DSPatrick answered ·

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


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




·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnJY-4666 avatar image
0 Votes"
JohnJY-4666 answered ·

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!

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The error message says that it couldn't retrieve the zone information. Without that there can be no search for the resource record.

You need to run that script on a DNS server that hosts the zone . . . or supply the name of a DNS server with the -Computer parameter on the Get-DnsServerResourceRecord cmdlet.

1 Vote 1 ·
DSPatrick avatar image
0 Votes"
DSPatrick answered ·

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--






·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnJY-4666 avatar image
0 Votes"
JohnJY-4666 answered ·

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!

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Glad to hear, you're welcome.




0 Votes 0 ·
JohnJY-4666 avatar image
0 Votes"
JohnJY-4666 answered ·

If a server is assigned multiple IP addresses with one NIC, the script failed. anyone knows how to convert to static instead of doing individually? thank you for your help!

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnJY-4666 avatar image
0 Votes"
JohnJY-4666 answered ·

If a dynamic host name with multiple IPs as the followings,
server1 10.1.1.1
server1 10.1.1.2
server1 10.1.1.3

the script failed with the following errors:

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 : PropertyAssignmentException

Set-DnsServerResourceRecord : Cannot process argument transformation on parameter 'NewInputObject'. Cannot convert the
"System.Object[]" value of type "System.Object[]" to type "Microsoft.Management.Infrastructure.CimInstance".
At line:5 char:46

Can anyone share how you resolve this issue?

Thank you for your help!


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.