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.