# Return other properties when using Select-String

**URL:** <https://forums.powershell.org/t/return-other-properties-when-using-select-string/176>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/return-other-properties-when-using-select-string/176 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/return-other-properties-when-using-select-string/176/1 "2011-12-31T18:30:00Z")

</div>

by SQLRunr at 2012-09-17 13:09:24

> I have a log object which has multiple properties, one of which has the log messages in a property called Text. Another property is the date/time of the message. I’m using the following command:  
>   
> $log | select-string -inputobject {$_.Text} -pattern ‘Error:’ -context 0,1_  
>   
> _Unfortunately it only returns what’s in the Text property. Is there a way to also return the other corresponding properties?_  
>   
> _Thanks._  
>   
> _Allen_

_by RichardSiddaway at 2012-09-17 13:30:58_

> _could you try something like this_  
>   
> _$data = $log | select-string -inputobject {$_.Text} -pattern ‘Error:’ -context 0,1  
>   
> if ($data){ do your stuff here }

by SQLRunr at 2012-09-17 14:38:07

> Unfortunately there’s no ‘key’ information in the Text property that could link back to the other properties. I was hoping that select-string with the -inputobject property would preserve that object integrity somehow.

by Klaas at 2012-09-18 00:44:44

> Do you mean your $log is a collection of log objects and you want to filter out the objects that contain ‘Error:’?  
>   
> Would this help you?:  
> `$log | Where {$.Text -match ‘Error:’} | Select Date,Text`

_by SQLRunr at 2012-09-18 12:18:14_

_> Thanks, Klaas but that returns a whole lot of blank rows if I add the context parameter. Looks like I’ll need to load the text file with the log rather than the log object. ☹_

_by Klaas at 2012-09-19 01:36:44_

> _Why exactly do you need the -context ? If it’s just to truncate the text, maybe you could use the substring method:_  
>   
> _`$log | Where-object {$`_`.Text -match ‘Error:’} | Select-object Date,@{name=‘message’,expression={$_.Text.substring(0,160)}}`  
>   
> If you would choose to work with text instead of objects, I think you’re going to have a lot more work with all the conversion and matching.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:02pm UTC](https://forums.powershell.org/t/return-other-properties-when-using-select-string/176/2 "2024-05-16T21:02:16Z")

</div>


