PowerShell script to move files and folders including subfolders from one location to another older than x days

前端 未结 4 2163
说谎
说谎 2021-02-13 02:10

I developed a PowerShell script, and it\'s working absolutely fine. The only challenge is the files in the subfolders are not getting moved to the destination.

g         


        
相关标签:
4条回答
  • 2021-02-13 02:24

    Don't waste your time trying to re-invent robocopy in PowerShell.

    robocopy \\servername\location C:\Dumps /e /mov /minage:31
    
    0 讨论(0)
  • 2021-02-13 02:32

    Use the -Recurse option on the Get-ChildItem command to get through to the files in the sub folders and then move each individually by piping the collection to Move-Item

    Get-ChildItem -Path "C:\Test" -Recurse |
      Where-Object {$_.LastWriteTime -lt (Get-date).AddDays(-31)} |
      Move-Item -destination "C:\Dumps"
    

    Here's a screenshot:

    0 讨论(0)
  • 2021-02-13 02:38

    Simplification of the above
    robocopy A:\ B:\ /MIR /minage:31
    Where A:\ is your source B:\ is your destination

    0 讨论(0)
  • 2021-02-13 02:46

    I needed a quick one liner to move all data off one drive onto another. This worked perfectly for me:

    Get-ChildItem "E:" -Recurse | Move-Item -Destination "G:"

    0 讨论(0)
提交回复
热议问题