Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell script to modify DNS not returning errors

$
0
0

I've modified a script to make DNS changes given a name/IP combo from a CSV file and it seems to be working, but is not throwing any errors (which I had thought it would do, but doesn't)

######################################
## Directions:
##
## Script Requires DnsShell 0.4.4 http://dnsshell.codeplex.com/ 
## Script Uses Get-Dns and New-DnsRecord
## csv file must be in following format including the proper first line headers
## Name,IPAddress
## eample_a_record,127.0.0.1
######################################

Write-Host "Enter Name the Path to the CSV File>"
$CSV = read-host
Write-Host "Enter Name the DNS Server>"
$ServerName = read-host
Write-Host "Enter the Domain example: domain.local>"
$ForwardLookupZone = read-host
$filename = "D_ERRLOG{0:yyyyMMdd-HHmm}.txt" -f (Get-Date) #error Log 
Write-Host "Enter The Reverse Domain Octet example 168.192 or 10 for 10.in-addr.arpa.>"
$TReverseLookupZone = read-host
$ReverseLookupZone = $TReverseLookupZone + ".in-addr.arpa."

# Import CSV and create A record

Import-Csv $CSV | ForEach-Object{

$record = get-dnsrecord -name $_.name -recordtype A -zonename $forwardlookupzone -Server $ServerName
if ($record.name) {get-dnsrecord -name $_.name -recordtype A -zonename $forwardlookupzone -Server $ServerName | Remove-DnsObject -force | out-file ./$filename -Append}
New-DnsRecord -name $_.name -recordtype A -zonename $forwardlookupzone -IPaddress $_.IPAddress -Server $ServerName | out-file ./$filename -Append

#create reverse record

New-DnsRecord -Name $_.IPAddress -Hostname ($_.name + '.' + $forwardlookupzone) -Zonename $ReverseLookupZone -Type PTR -Server $ServerName | out-file ./$filename -Append
}

Write-Host -foreground "yellow" "Any Errors will be in the file $filename"

The out-file is blank, every time. I've even forced errors but it's still blank.

Any ideas? 

Thank you.


zarberg@gmail.com


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>