locked
How to show full file path in results RRS feed

  • Question

  • Hi,

    I've been trying to make the script from https://blogs.technet.microsoft.com/heyscriptingguy/2014/02/07/use-powershell-to-find-files-that-have-not-been-accessed/ show the full file path. 

    The script looks like this

    Function Get-NeglectedFiles
    
    {
    
     Param([string[]]$path,
    
           [int]$numberDays)
    
     $cutOffDate = (Get-Date).AddDays(-$numberDays)
    
     Get-ChildItem -recurse -Path $path |
    
     Where-Object {$_.LastAccessTime -le $cutOffDate}
    
    }

    And I've been trying to use the knowledge in this post to do so. 

    http://stackoverflow.com/questions/13126175/get-full-path-of-the-files-in-powershell

    Yet to no avail. Does anyone know?

    Thursday, November 17, 2016 1:01 PM

Answers

  • ..... your code ...  | Select-Object -Property FullName
    or
    ..... your code ...  | Select-Object -ExpandProperty FullName


    Grüße - Best regards

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

    • Proposed as answer by Vincent Karunaidas Friday, November 18, 2016 7:04 AM
    • Marked as answer by Hmerstrand Friday, November 18, 2016 8:54 AM
    Thursday, November 17, 2016 1:07 PM

All replies

  • ..... your code ...  | Select-Object -Property FullName
    or
    ..... your code ...  | Select-Object -ExpandProperty FullName


    Grüße - Best regards

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

    • Proposed as answer by Vincent Karunaidas Friday, November 18, 2016 7:04 AM
    • Marked as answer by Hmerstrand Friday, November 18, 2016 8:54 AM
    Thursday, November 17, 2016 1:07 PM
  • I am sure you are right, but I've been unable to fir it into the script and make it work.

    Where do I add the text in the formula?

    Friday, November 18, 2016 8:54 AM
  • Hmmmm ... you really should start to learn Powershell. I am sure it will pay off in the future for you.

    Well, as usual there are several ways you can deal with that. The most flexible way is you just use the function as always and pipe the result to change it to whatever you need:

    Get-NeglectedFiles -Path C:\Temp -NumberDays 25 |  Select-Object -Property FullName
    or if you want to have the result 'naked' 
    Get-NeglectedFiles -Path C:\Temp -NumberDays 25 |  Select-Object -ExpandProperty FullName
    or, when you always want to have this experience you can put it in the function
    Function Get-NeglectedFiles
    {
        Param([string[]]$path,
            [int]$numberDays)
        $cutOffDate = (Get-Date).AddDays(-$numberDays)
        Get-ChildItem -recurse -Path $path |
        Where-Object {$_.LastAccessTime -le $cutOffDate} |  
        Select-Object -Property Mode,LastWriteTime,Length,FullName
    }
    (if you want to get rid of the other properties you can just delete them)



    Grüße - Best regards

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

    Friday, November 18, 2016 10:02 AM