Some times you have an list of psobject with empty properties values (which will distract you from the important properties). I think it should be possible with format-list to skip such properites without any third-party function
I'm not alone:
https://stackoverflow.com/a/44370806/410540
I propose:
-skipEmty will not show you the noteProperties which have null or empty strings
or may be:
-skipPattern "^$|^s+$"
Simulating the expected output:
New-Object PSObject -Property @{"a"=$null; "b"="b"; "c"="c"} | fl | out-string -Stream | sls -NotMatch "^[^:]*:s+$"
Thank you!
We have Where-Object cmdlet for filtering. It is not clear why we should move Where-Object functionality to formatting cmdlets.
Sorry I did not explain (this is not a where-object funcionality). See this example ($person have a list of person data):
$person | fl
Name: Jorge
City: Jaen
Telephone:
Name: Juan
City: M谩laga
Telephone: 666555444
$person | fl -skipEmpty
Name: Jorge
City: Jaen
Name: Juan
City: M谩laga
Telephone: 666555444
See Telephone of Jorge is not presente because It is empty
The same idea could be with -skipPattern
This parameter apply better with objects with many noteProperties like those created with importfrom-csv using a csv with many columns
Sorry for my english
For the case you can do:
$person | Where-Object Telephone | fl
For the case you can do:
$person | Where-Object Telephone | fl
I have not powershell to exec this now but I think It would skip Jorge info (not only not show Telephone in the output)
I Will test ir later
Think about a larger csv import. If there are many empty properties this parameter would be very useful to inspect the data from command line
Thank you very much!
I have not powershell to exec this now but I think It would skip Jorge info (not only not show Telephone in the output)
That's correct. Where-Object is not designed to skip individual properties on objects, only whole objects based on a given condition.
This request is different, I think. Asking Format-List to simply skip individual properties on every object if they're null or empty is definitely useful in some cases, there are cases where some objects may have many null properties that the user doesn't care to display.
Currently the closest thing you can do here is something like this:
$PropertiesShown = $person.PSObject.Properties.Where{$_.Value}.Name
$person | Select-Object -Property $PropertiesShown | Format-List
We could definitely stand to add a switch to make this more accessible.
I have not powershell to exec this now but I think It would skip Jorge info (not only not show Telephone in the output)
That's correct. Where-Object is not designed to skip individual properties on objects, only whole objects based on a given condition.
This request is different, I think. Asking Format-List to simply skip individual properties on every object if they're null or empty is definitely useful in some cases, there are cases where some objects may have many null properties that the user doesn't care to display.
Currently the closest thing you can do here is something like this:
$PropertiesShown = $person.PSObject.Properties.Where{$_.Value}.Name $person | Select-Object -Property $PropertiesShown | Format-List
It is (but with foreach ($p in $person) ir similar loop)
Thank you!
Most helpful comment
That's correct. Where-Object is not designed to skip individual properties on objects, only whole objects based on a given condition.
This request is different, I think. Asking Format-List to simply skip individual properties on every object if they're null or empty is definitely useful in some cases, there are cases where some objects may have many null properties that the user doesn't care to display.
Currently the closest thing you can do here is something like this:
We could definitely stand to add a switch to make this more accessible.