Noob question sorry if very obvious

Hi Everyone, my apologies in advance if this is a stupid question but I am working through the PowerShell in a month of lunches by Don Jones, and I’m stuck on a problem from Chapter 11. I need to use Get-DnsClientCache and display a list of A and AAAA records from cache. The problem I am having is I am unable to find the property “RecordType” to complete this. I’ve tried

 Get-DnsClientCache | GM 
and
 Get-DnsClientCache | Select-Object * 
to see if I am missing any aliased properties but I am unable to find them.

I’ve checked the full help and am just stuck at this point. I dont want to just look at the answer in the book as that wont give me an understanding on how I can go find properties like this in the future for any other cmdlets. Thank you all for your help.

Did you try simply

Get-DnsClientCache
? How does the output looks like?
Did you try
Get-DnsClientCache -Type AAAA,A
? Is this the result you’re looking for?

Got it, its because of the formatting system. The actual property is Type and the default formatting for DNSClient module(Where this cmdlet is from) changes it to Record Type

I did a blog post a while back explaining similar behaviour for the another cmdlet from the same module. There the formatting was applied to the value, here its on the Property.
Hint: You can check the third property in the view section of the formatting xml for this module.

http://www.viapowershell.com/2016/06/hidden-formatting.html

Thanks so much for your help and write up. I did visit it and using your script I was able to open up the formating for Get-DnsClientCache and did find the information below showing how the proparty name is “type” but like you mentioned is aliased to “recordType”.

I really appreciate your help as this is something I can use continue to use in the future for any other similar situations.

 

Hi Olaf, and thanks for your help my main problem was that when I did run the cmdlet I was not aware that “RecordType” and “Type” where the same field but just aliased. Thanks again for your help.

Weird, recordtype appears in “get-dnsclientcache | select -first 1 | fl”, but not “get-dnsclientcache | select -first 1 | fl *”. I guess that’s how the view in the format file is setup? (CimInstance object)(or not).

PS C:\users\admin> get-dnsclientcache | select -first 1 | fl


Entry      : njpl.yumenetworks.com
RecordName : njpl.yumenetworks.com
RecordType : A
Status     : Success
Section    : Answer
TimeToLive : 2244
DataLength : 4
Data       : 199.127.206.130



PS C:\users\admin> get-dnsclientcache | select -first 1 | fl *


TTL                   : 2240
Caption               :
Description           :
ElementName           :
InstanceID            :
Data                  : 199.127.206.130
DataLength            : 4
Entry                 : njpl.yumenetworks.com
Name                  : njpl.yumenetworks.com
Section               : 1
Status                : 0
TimeToLive            : 2240
Type                  : 1
PSComputerName        :
CimClass              : ROOT/StandardCimv2:MSFT_DNSClientCache
CimInstanceProperties : {Caption, Description, ElementName, InstanceID, Data, DataLength, Entry, Name, Section,
                        Status, TimeToLive, Type}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

The default is Table view and when we do Format-List, it uses the list view(search for DnsClientCacheListView in the formatting xml).
When you do Format-List * , AFAIK its again the same…

I don’t believe “| fl *” uses the format file. Ok, I found “DnsClientCacheListView” in C:\WINDOWS\System32\WindowsPowerShell\v1.0\Modules\DnsClient\DnsConfig.Format.ps1xml. RecordType is generated like this. Some of the tags don’t show in this forum. Using headers that don’t match property names is confusing (especially in list view). I guess the object type is “Microsoft.Management.Infrastructure.CimInstance#MSFT_DNSClientCache”. “| ft *” would avoid the format file as well, but that’s not as convenient.

 <Label>RecordType</Label>
                <ScriptBlock>
                  $type = $_.Type
                  $typefmt = switch ($type)
                  {
                      0       {"ZERO"}
                      1       {"A"}
                      2       {"NS"}
                      5       {"CNAME"}
                      6       {"SOA"}
                      12      {"PTR"}
                      15      {"MX"}
                      16      {"TEXT"}
                      24      {"SIG"}
                      25      {"KEY"}
                      28      {"AAAA"}
                      30      {"NXT"}
                      33      {"SRV"}
                      35      {"NAPTR"}
                      37      {"CERT"}
                      39      {"DNAME"}
                      41      {"OPT"}
                      43      {"DS"}
                      46      {"RRSIG"}
                      47      {"NSEC"}
                      48      {"DNSKEY"}
                      49      {"DHCID"}
                      50      {"NSEC3"}
                      51      {"NSEC3PARAM"}
                      255     {""}
                      default {$type}
                  }
                  return $typefmt
                </ScriptBlock>