Hello,
I’m having trouble using the Where-Object
to filter some output.
I’m creating an object for some json data, and although I can list key properties, I can’t seem to filter my results to get “whatever” key(s) I want.
Here’s my process flow:
$object = Get-Content -Path D:\Outfile_MP4.json | ConvertFrom-Json # create object from json file
$object | Get-Member # reveals two NoteProperty objects: 'format' and 'streams'
#sample output
format NoteProperty System.Management.Automation.PSCustomObject format=@{filename=D:\Movies\12 Angry Men (1957).mp4;
streams NoteProperty Object[] streams=System.Object[]
Focusing on the format object:
$object.format | Select-Object -Property * | Format-List # outputs 'keys' and 'values' in list
filename : D:\Movies\12 Angry Men (1957).mp4
nb_streams : 3
nb_programs : 0
format_name : mov,mp4,m4a,3gp,3g2,mj2
format_long_name : QuickTime / MOV
start_time : 0.000000
duration : 5769.930833
size : 10848568174
bit_rate : 15041522
probe_score : 100
tags : @{major_brand=mp42; minor_version=512; compatible_brands=mp42iso6; creation_time=2022-03-04 05:09:52; title=12 Angry Men (1957); comment=Henry Fonda, Lee J. Cobb, Ed Begley
and Jack Klugman lead in this tense, courtroom drama - nominated for three Oscars including Best Picture - about one juror determined to sway the opinions of eleven others.}
$object.format | Select-Object -Property * | Get-Member
TypeName: Selected.System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
bit_rate NoteProperty string bit_rate=15041522
duration NoteProperty string duration=5769.930833
filename NoteProperty string filename=D:\Movies\12 Angry Men (1957).mp4
format_long_name NoteProperty string format_long_name=QuickTime / MOV
format_name NoteProperty string format_name=mov,mp4,m4a,3gp,3g2,mj2
nb_programs NoteProperty long nb_programs=0
nb_streams NoteProperty long nb_streams=3
probe_score NoteProperty long probe_score=100
size NoteProperty string size=10848568174
start_time NoteProperty string start_time=0.000000
tags NoteProperty System.Management.Automation.PSCustomObject tags=@{major_brand=mp42; minor_version=512; compatible_brands=mp42iso6; creation_time=2022-03-04 05:09:52; title=12 An…
($object.format | Get-Member -Name *).Name # outputs keys only
Equals
GetHashCode
GetType
ToString
bit_rate
duration
filename
format_long_name
format_name
nb_programs
nb_streams
probe_score
size
start_time
tags
My attempt at trying to filter the output from either of the above outputs:
$object.format | Select-Object -Property | Where-Object -Property Equals 'filename'
$object.format | Select-Object -Property * | Where-Object -Property Equals "filename"
$object.format | Select-Object -Property * | Where-Object -Property Equals "*name*"
POSH just outputs an error that I’m doing it all wrong…
I’m trying to figure out how I can search for a specified key(s) and…
- output those ‘filtered’ keys in a list
- output those ‘filtered’ keys and their respective values in a list.
Thanks for any help or guidance with this…