Difference between revisions of "Powershell snippets"
Jump to navigation
Jump to search
(Created page with "# Powershell Snippets ## Get A/CNAME DNS Records from Windows DNS get-dnsRecords.ps1 ``` $ErrorActionPreference = "Stop" if ($args.Count -lt 1) { Write-Host "Usage: ge...") |
|||
Line 8: | Line 8: | ||
if ($args.Count -lt 1) { | if ($args.Count -lt 1) { | ||
Write-Host "Usage: get-dnsRecords.ps1 <zone name/domain>" | Write-Host "Usage: get-dnsRecords.ps1 <zone name/domain>" | ||
− | Write-Host "Example: get-dnsRecords.ps1 | + | Write-Host "Example: get-dnsRecords.ps1 example.com" |
exit 1 | exit 1 | ||
} | } |
Revision as of 14:53, 19 January 2024
Powershell Snippets
Get A/CNAME DNS Records from Windows DNS
get-dnsRecords.ps1
$ErrorActionPreference = "Stop" if ($args.Count -lt 1) { Write-Host "Usage: get-dnsRecords.ps1 <zone name/domain>" Write-Host "Example: get-dnsRecords.ps1 example.com" exit 1 } $zoneName = $args[0] # write-host "$zoneName" # exit $rsp = Invoke-Command -ComputerName wjp1-dc -ScriptBlock { param($zoneName) $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 write-output "$rsp" | Out-File -FilePath ".\$($zoneName).records" write-host "Records are in in file .\$($zoneName).records"