Data missing when Select-Object in use

Microsoft Windows
Post Reply
lazna
Posts: 8
Joined: 2022-Jun-19, 1:48 pm

Data missing when Select-Object in use

Post by lazna »

Why some data missing in output via Select-Object

Code: Select all

powershell "Get-DnsClientCache -Entry *whitehouse.org | select-object -property Entry,RecordName,RecordType,Status,Selection,TimeToLive,DataLenght,Data"

Entry      : whitehouse.org
RecordName :
RecordType :
Status     : 0
Selection  :
TimeToLive : 8858
DataLenght :
Data       : 158.69.60.9
compare to output without Select-Object

Code: Select all

powershell "Get-DnsClientCache -Entry *whitehouse.org"

Entry                     RecordName                Record Status    Section TimeTo Data   Dat
                                                    Type                     Live   Length a
-----                     ----------                ------ ------    ------- ------ ------ ---
whitehouse.org            whitehouse.org            A      Success   Answer    8811      4 158
Just notice if you want to test it, you have to perform

Code: Select all

ping whitehouse.org
prior, to get record to your DNS cache
User avatar
Simon Sheppard
Posts: 102
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: Data missing when Select-Object in use

Post by Simon Sheppard »

This is standard behaviour when you ask PowerShell for more data than will fit across the screen.

Solutions:
1) Just make the window wide enough so it will fit.
2) Pipe the output to | format-table -auto (this may still truncate but it will try a bit harder to display everything).
3) Send the output to a file with | out-file c:\batch\output.txt
4) Save the result in a variable and then use one property at a time – this is usually the best approach because you are saving the entire object with all its properties and methods available to you:

Code: Select all

$result = Get-DnsClientCache -Entry *whitehouse.org
($result).data
lazna
Posts: 8
Joined: 2022-Jun-19, 1:48 pm

Re: Data missing when Select-Object in use

Post by lazna »

You probably not fully understand me. My question was not why screen lines are truncated, but why in first example missing some values (compate to second example in my first post)

BTW:

To prevent lines truncate using pipe output to

Code: Select all

Write-Host -width 999
lazna
Posts: 8
Joined: 2022-Jun-19, 1:48 pm

Re: Data missing when Select-Object in use

Post by lazna »

Interesting, it reformate data dependent as long the output will be. When number of properties are <=4 it format output as table, but when number of requested properties is >4 than output is formated each line, single pair:

Code: Select all

Name : Value
But still some values missing in output of all eight properties formated line by line
User avatar
Simon Sheppard
Posts: 102
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: Data missing when Select-Object in use

Post by Simon Sheppard »

Ah I see what you mean.

I think this is one of those annoying cases where the columns have a 'display name' to prettify the output.

To get the real property names you can select/filter on, you need to do:

Code: Select all

Get-DnsClientCache | Format-List -Property * -Force
lazna
Posts: 8
Joined: 2022-Jun-19, 1:48 pm

Re: Data missing when Select-Object in use

Post by lazna »

Thats it! Thanks...
Post Reply