none
Powershell help in Select Object RRS feed

  • Question

  • Hi All,

    I have the following to get the LastWriteTime as part of the Select Object but it is not providing any ouput. Do I know what I am doing wrong in the following code segment?  Please help me out

    @{Name = 'LT';Expression = {($_.LastWriteTime)}}

    Get-ChildItem -Path "$Loc" -Recurse -Include $Extensions -ErrorAction SilentlyContinue| Select-String -Pattern $Pattern | Select-Object Path, Filename, Pattern, LineNumber, Line,@{Name="APPID"; Expression={$values}},@{Name = 'LT';Expression = {($_.LastWriteTime)}}

    Monday, July 1, 2019 8:53 PM

All replies

  • Assumed you have the path to the folder where you want to start in the variable $Loc and the extensions you're after in the variable $Extensions this should be enough
    Get-ChildItem -Path $Loc -Recurse -Include $Extensions -ErrorAction SilentlyContinue | 
        Select-Object Path, Filename, Pattern, LineNumber, Line, LastWriteTime


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Monday, July 1, 2019 9:10 PM
  • If you are trying to run a RegEx on the contents of a file then a bit more is needed.


    \_(ツ)_/

    Monday, July 1, 2019 9:22 PM
  • Here is how to get that info when matching the contents of a file.

    $select = @(
        'Path', 
        'Filename', 
        'Pattern',
        'LineNumber', 
        'Line', 
        @{n = 'APPID'; e = {$values}}, 
        @{n = 'LastWriteTime'; e = {$fi.LastWriteTime}}
    )
    $loc = 'your path'
    $extensions = '*.*'
    $pattern = 'your pattern'
    $values = 'unknown'
    
    Get-ChildItem -Path $loc -Recurse -Include $extensions -PipelineVariable fi -ErrorAction SilentlyContinue| 
        Select-String -Pattern $pattern | 
        Select-Object $select
    


    \_(ツ)_/


    • Edited by jrv Monday, July 1, 2019 9:34 PM
    Monday, July 1, 2019 9:34 PM
  • Thank you very much for your help.  
    Tuesday, July 2, 2019 4:06 PM