Find files based on LastAccessTime and move to new location

This topic contains 4 replies, has 3 voices, and was last updated by  ShiftNick 2 years, 6 months ago.

  • Author
    Posts
  • #24205

    ShiftNick
    Participant

    I'm trying to move any files that have not been access in two years to lower tier storage and I'm not sure the best way to make the moves. I would like to keep the directory structure intact and I have a feeling I should be using robocopy but I'm not sure the correct way to pipe the results of my script in to a robocopy script.

    This is the line I'm using the find the files.

    $cutOffDate = (Get-Date).AddDays(-730)
    Get-ChildItem -Path '\\file-server\s$\files\' -Recurse | Where-Object {$_.LastAccessTime -le $cutOffDate} | Select-Object -Property Name,LastAccessTime | Out-file -FilePath "C:\Temp\FilesLastAccessed.txt"

    Any pointers on how to dump the results into a robocopy script or achieve my intended result?

  • #24212

    notarat
    Participant

    The following would do what you want, but would fail if a file is open or locked
    [code]ROBOCOPY C:\SourceFolder C:\destination /move /minlad:730[/code]

  • #24215

    Rob Simmers
    Participant

    Keep in mind that LastAccessed* information isn't always what you want. When Antivirus programs scan files, it can change those values for instance. Typically, you want to use the LastModified properties for comparisons that indicate the last time something was changed in a file.

    • #24222

      ShiftNick
      Participant

      Keep in mind that LastAccessed* information isn't always what you want. When Antivirus programs scan files, it can change those values for instance. Typically, you want to use the LastModified properties for comparisons that indicate the last time something was changed in a file.

      While I would normally agree with you, we have a large number of files that are accessed but not edited and moving them could break some processes.

  • #24221

    ShiftNick
    Participant

    That did not work for some reason and I can't see why. Very strange indeed.

    When I run my Powershell script, I get over 1600 results, which is even more puzzling.

You must be logged in to reply to this topic.