0

I am trying to create a new folder on google drive and append the date and hour to the end of it to create a rolling 1 hour backup with old versions still accessible. I am not knowledgeable enough about PowerShell in order to automatically delete folders over 7 days old so I have to do it manually. The problem seems to be when PowerShell creates the new folders and copies the files, I no longer have access to delete them. I have checked permissions and added Everyone, Administrators, and the current user (the only user and admin) and it still will not allow me to delete the folders that PowerShell creates. I can delete files I manually put into Google drive. Here is my code:

$yest = (Get-Date).AddDays(-1).ToString(‘hhMMddyy’)
mkdir "C:\Users\admin\Google Drive\SpaceEngineersDedicated.$yest" -Force
Copy-Item C:\Users\admin\AppData\Roaming\SpaceEngineersDedicated -Destination "C:\Users\admin\Google Drive\SpaceEngineersDedicated.$yest" -Recurse -Force

If someone could help me with code that will just delete folders over 7 days, I would appreciate it but worst case scenario I'm fine with occasionally cleaning them up manually.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Laser411
  • 43
  • 5
  • 1
    What do you mean "have no longer access to delete them"? You didn't show any code that'd delete something. Did you try `Remove-Item` on a folder? Do you get errors? What do they say? – Ansgar Wiechers Jul 30 '16 at 18:59
  • I'm talking about manual deletion of the files copied. Something about this script is messing up the permissions in a way that I can't seem to understand. It says the owner is the 1 and only user on the system but it gives me the famous windows message "you need permission to perform this action" – Laser411 Jul 30 '16 at 23:29
  • Check if something is still keeping an open handle to that folder (with [`handle`](https://technet.microsoft.com/en-us/sysinternals/bb896655) or [Process Explorer](https://technet.microsoft.com/en-us/sysinternals/processexplorer)). – Ansgar Wiechers Jul 31 '16 at 00:03
  • Possible duplicate of [Delete files older than 15 days using PowerShell](http://stackoverflow.com/questions/17829785/delete-files-older-than-15-days-using-powershell) – TessellatingHeckler Jul 31 '16 at 00:26

0 Answers0