Get-DnsClientCache converts/displays an integer for RecordType

Microsoft Windows
Post Reply
cmcghee92
Posts: 1
Joined: 2023-Aug-23, 12:28 am

Get-DnsClientCache converts/displays an integer for RecordType

Post by cmcghee92 »

String Values are being converted or displayed as integers when piped to Select. How can this be overcome to keep the values outputted as strings Note: RecordType and Status
clip1.JPG
clip1.JPG (26.78 KiB) Viewed 10163 times
clip2.JPG
clip2.JPG (19.91 KiB) Viewed 10163 times
User avatar
Simon Sheppard
Posts: 191
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: Get-DnsClientCache converts/displays an integer for RecordType

Post by Simon Sheppard »

Getting sensible values out of this was harder than I expected, they are both hard coded and in [uint16] so you will need something like this:

Code: Select all

# Hash table of Types
$dnstypes = @{
   [uint16]1 = "A"
   [uint16]2 = "NS"
   [uint16]5 = "CNAME"
   [uint16]6 = "SOA"
   [uint16]12 = "PTR"
   [uint16]15 = "MX"
   [uint16]28 = "AAA"
   [uint16]33 = "SRV"
}
# via https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh872334(v=vs.85)

# Hash table of Status
$dnsStatus = @{
   [uint32]0 = "Success"
   [uint32]9003 = "NotExist"
   [uint32]9701 = "NoRecords"
}
   
get-dnsclientcache | select name,type, status | ForEach-object {
   $out=$_.name + " = " + $dnstypes[$_.type] + " = " + $dnsStatus[$_.status]
   $out
}
Post Reply