Difference between revisions of "Powershell snippets"

From UVOO Tech Wiki
Jump to navigation Jump to search
Line 15: Line 15:
 
$zoneName = $args[0]
 
$zoneName = $args[0]
 
$dnsHost = $args[1]
 
$dnsHost = $args[1]
 
# write-host "$zoneName"
 
# exit
 
  
 
$rsp = Invoke-Command -ComputerName wjp1-dc -ScriptBlock {
 
$rsp = Invoke-Command -ComputerName wjp1-dc -ScriptBlock {

Revision as of 14:59, 19 January 2024

Powershell Snippets

Get A/CNAME DNS Records from Windows DNS

get-dnsRecords.ps1

$ErrorActionPreference = "Stop"

if ($args.Count -lt 2) {
    Write-Host "Usage:   get-dnsRecords.ps1 <zone name/domain> <windows dns hostname>"
    Write-Host "Example: get-dnsRecords.ps1 example.com my-windows-dns-host"
    exit 1
}

$zoneName = $args[0]
$dnsHost = $args[1]

$rsp = Invoke-Command -ComputerName wjp1-dc -ScriptBlock {
  param($zoneName, $dnsHost)
  $dnsRecords = Get-DnsServerResourceRecord -ZoneName $zoneName -RRType A
  foreach ($record in $dnsRecords) {
    Write-Output "$($record.HostName).$zoneName"
  }
  $dnsRecords = Get-DnsServerResourceRecord -ZoneName $zoneName -RRType CName
  foreach ($record in $dnsRecords) {
    Write-Output "$($record.HostName).$zoneName"
  }
} -ArgumentList $zoneName, $dnsHost
write-output "$rsp" | Out-File -FilePath ".\$($zoneName).records"
write-host "Records are in in file .\$($zoneName).records"