locked
Use Filter attribute with Get-Content RRS feed

  • Question

  • I'm trying to figure out the proper syntax to apply the -Filter attribute in conjunction with a Get-Content cmdlet. 

    I've tried several variations of Get-Content -Path myfile.txt -Filter mystring and I get an error message. How is this supposed to work?  I have not found any example anywhere.

    Thanks.

    Thursday, February 2, 2017 11:52 PM

Answers

  • Thank you. I misunderstood that the filter is applied to the path not to the contents of the file. 
    • Marked as answer by Geol4549 Friday, February 3, 2017 1:45 AM
    Friday, February 3, 2017 1:43 AM
  • Get-Content works like Get-Childitem and can process files based on many of the same parameters of Get-Childitem.

    Get-Content *.* -filter X??Text.txt

    To prcoess the content of files:

    Get-Content *.* -filter X??Text.txt  | ?{ Select-String 'ronny slept here [miami|new york|paris|berlin'  }


    \_(ツ)_/

    • Marked as answer by Geol4549 Friday, February 3, 2017 3:10 AM
    Friday, February 3, 2017 2:16 AM

All replies

  • Filter takes a file template,

    Get-Content  -filter t?s*.txt


    \_(ツ)_/

    Friday, February 3, 2017 1:14 AM
  • Thank you. I misunderstood that the filter is applied to the path not to the contents of the file. 
    • Marked as answer by Geol4549 Friday, February 3, 2017 1:45 AM
    Friday, February 3, 2017 1:43 AM
  • Get-Content works like Get-Childitem and can process files based on many of the same parameters of Get-Childitem.

    Get-Content *.* -filter X??Text.txt

    To prcoess the content of files:

    Get-Content *.* -filter X??Text.txt  | ?{ Select-String 'ronny slept here [miami|new york|paris|berlin'  }


    \_(ツ)_/

    • Marked as answer by Geol4549 Friday, February 3, 2017 3:10 AM
    Friday, February 3, 2017 2:16 AM