question

SethRoberts-0739 avatar image
0 Votes"
SethRoberts-0739 asked SethRoberts-0739 commented

Script to Change Permissions on DNS Records

I've found myself in a situation where some computers in our environment are not able to update their records in DNS when their IP address changes. This is primarily due to DHCP servers creating the record on their behalf when the DHCP server issues or renews leases. Needless to say, PowerShell isn't my strength. I need to find a way to add an ACL for the computer object to have modify rights of its DNS record. Scripting this seems like the fastest and most reliable way to accomplish this. I would very much appreciate any help the PowerShell experts can provide.
Best,
Seth

windows-server-powershellwindows-dhcp-dns
5 |1600 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.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered SethRoberts-0739 commented

Hi,

Please see if this works for you. Set $ComputerNames to your actual computer names.

 $ComputerNames = "computer1","computer2","computer3"
 foreach($ComputerName in $ComputerNames){
     $DNSServer = (Get-ADDomain).PDCEmulator 
     $ZoneNames = Get-DnsServerZone -ComputerName $DNSServer
     $DNSRecord = foreach($ZoneName in $ZoneNames ){
         Get-DnsServerResourceRecord -ComputerName $DNSServer -ZoneName $ZoneName.ZoneName | Where-Object {$_.hostname -eq $ComputerName}
     }
     $ADcomputer = Get-ADComputer -Identity $ComputerName
     $SID = New-Object System.Security.Principal.SecurityIdentifier $ADcomputer.SID.Value
     Push-Location -Path AD:\
     $ACL = Get-Acl -Path $DNSRecord.DistinguishedName
     $ACE = New-Object System.DirectoryServices.ActiveDirectoryAccessRule $SID, "GenericAll", "Allow"
     $ACL.AddAccessRule($ACE)
     $ACL | Set-Acl -Path $DNSRecord.DistinguishedName
     Pop-Location
 }

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 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.

Thank you so much for your help! I tested it and it works well. The only thing I made a change to was the variable for computer names to $ComputerNames = get-content -path c:\temp\computers.txt

Thanks again for your time and expertise!
Seth

0 Votes 0 ·