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.