Home > Mobile >  Old powershell move-item script not working on new os
Old powershell move-item script not working on new os

Time:01-27

I've got this powershell script

get-childitem -File -filter "*.m4a" -Path "C:\directory\live" -Recurse |
    where-object {$_.LastWriteTime -lt (get-date).AddDays(-61)} | 
    move-item -destination "C:\directory\temp"

It worked on my previous W11, but now I have a new pc and new disk, so I've installed fresh W11 and this sript is not working there. Only thing I changed was from $.CreationTime to $.LastWriteTime (because after copying to the new disk all files gained new creation date, but last write date stayed the same, so I have to rely on this thing for the first 61 days) and from D to C drive, because now I have only one disk. I tried using copy-item, but it also does not work. I don't get any error, the script just goes through and does nothing. Both directories exist and live has many files, some of which have last write date older than 61 days (But all of them have creation date 20 days ago). I could move them manually for 41 days, but it would be definetely easier to do this with a simple script now (and I can't be guaranteed it will work again when I change back to CreationTime).

CodePudding user response:

I was stupid enough to forget about powershell scirpt running policy. And that makes total sense - I've installed a new system so it was again fully restricted. I don't know why I didn't thought of that earlier, but now I changed it and it works. But thank you all for every answer.

  • Related