Reputation: 15
I have a script that reads a text file, captures specific string values via select-string and then writes to a csv file. The issue I am having is it automatically adds additional columns I do not want:
IgnoreCase LineNumber Line Filename Path Pattern Context Matches
The string values I want are under Line - How do I have it output ONLY the string values I have captured?
Upvotes: 1
Views: 1126
Reputation: 174505
Use Select-Object -ExpandProperty
to grab just a single property value from the MatchInfo
object that Select-String
returns:
$MatchedStrings = Get-Item C:\Windows\system32\WindowsPowerShell\v1.0\en-US\about_Foreach.help.txt |select-string "operator"
$MatchedStrings | Select-Object -ExpandProperty Line | Out-File C:\myStrings.txt
If you want to output to a single-column CSV file and retain the Line
header, use Select-Object -Property
instead:
$MatchedStrings | Select-Object -Property Line | Export-Csv C:\strings.csv -NoTypeInformation
Upvotes: 1