Created
August 3, 2022 14:15
-
-
Save gmirsky/1813b265eb2940bc17cf39f0167cb5eb to your computer and use it in GitHub Desktop.
Route 53 Inventory PowerShell Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Inventory-RT53-Zone-Records.ps1 | |
#Get a Full List of all records from all RT53 Zones, OR only for a targeted Zone set by Variable | |
#Also can get list for a single targeted Record Type, example TXT, MX etc | |
# ****** This WILL NOT export any records with "_domainkey" in the Name (url) for security reasons. | |
#Version: 1.5 | |
#Tested with Windows Powershell: 5.1, 7.0.3 | |
#Tested with MacOS PowerShell : 7.0.3 | |
#Date 10/23/2020 | |
#Modified 8/03/2022 | |
#Created: Ed Walsh | |
#Set $Domain to a SINGLE targeted RT53 Zone domain, example "mydomain.com" or get for ALL RT53 Zones by using "" | |
$Domain = "infocume.com" | |
#Set $Type for a SINGLE targeted Record Type, example "MX" or get all A, AAAA, CName records by using "" | |
$Type = "" | |
####################### | |
$DScope = If ($Domain -eq "") { "All-RT53-Zones" } else { $Domain+"-RT53-Zone"} | |
$Tscope = If ($Type -eq "") { "all-Record-Types" } Else { $Type+"-Record-Type" } | |
$timestamp = get-date -format yyyyMMddHHmmss | |
$subfolder = if (($PSVersionTable.PSEdition) -eq "Core") { if ( $True -eq $iswindows ) { "\Documents\" } Else { "" } } Else {"\Documents\"} | |
$mydocuments = $home + $subfolder #Old Way of doing it# [environment]::getfolderpath("mydocuments") | |
$fileName = "Rt53-"+$Tscope+"-Inventory-for-"+$DScope+"-"+ [string]$timestamp + ".csv" | |
$filePath = Join-Path $mydocuments $fileName | |
$rt53out = @() | |
####################### | |
$zones = Get-R53HostedZones | |
#foreach($url in $list) { $url.TrimEnd(".") } | |
foreach ($zone in $zones) { | |
$rt53out += if ($Domain -eq "" -or $zone.Name -eq "$Domain." ) { | |
<# When values are in a collection/array the output is controlled by $FormatEnumerationLimit | |
Setting it to -1 means unlimited #> | |
$FormatEnumerationLimit = -1 #This is a setting to prevent Truncating an Select-Object -ExpandProperty | |
$zname = $zone.Name | |
$(Get-R53ResourceRecordSet -HostedZoneId $($zone.Id)).ResourceRecordSets | Where-object { ($_.Name -notlike "*_domainkey*") } | Select-Object @{Name = 'RT53_Zone'; Expression = { $zname.Substring(0, $zname.Length - 1) } }, @{Name = 'URL'; Expression = { $_.Name.Substring(0, $_.Name.Length - 1) } }, Type,TTL,Failover, @{Name = "IsAlias"; Expression = { if ($_.AliasTarget -ne $null) { "True" } Else { "False" } } } , @{Name = 'Target'; Expression = { if ($_.AliasTarget -ne $null) { (($_.AliasTarget).DNSName).TrimEnd(".") } Else { ($_.ResourceRecords | Select-Object -ExpandProperty Value).TrimEnd(".") } } } | |
} | |
} | |
# $rt53out | Out-Gridview |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment