Hi,
I've written a powershell script which removes folders more than 7 days old. It seems to be removing the folders, but for some reason its giving me errors. I was wondering if anyone might be able to tell me why?
The script is...
$rootBackupFolder = "\server\share"
get-childitem $rootBackupFolder | where {$.PSIsContainer -AND $.Name -match ("^CVSRepository_(19|20)[0-9]0-9(0[1-9]|[12][0-9]|3[01])$") -AND $_.LastWriteTime -le (Get-Date).AddDays(-7)} | remove-item -recurse -force
Their are 2 errors I get, this first is this one...
- (Get-Date).AddDays(-7)} | remove-item <<<< -recurse -force Remove-Item : Cannot remove item \server\share\CVSRepository_20100305\somesubfolder\sumotherfolder: Could not find a part of the path '\server\share\CVSRepository_20100305\somesubfolder\sumotherfolder'.
The other error is this...
- (Get-Date).AddDays(-7)} | remove-item <<<< -recurse -force Remove-Item : Cannot remove item \server\share\CVSRepository_2010031 2\somesubfolder\: Access to the path 'Rdl' is denied.At C:\CVSRepository_BackupScript\Backup.ps1:43 char:38+ (Get-Date).AddDays(-7)} | remove-item <<<< -recurse -force
Any ideas? The script is running under a domain account which has privs to delete the remote folders. And in fact it is indeed deleting the folders! But giving me errors...
Thanks, Lachlan