locked
Deleting Old Backup's with Powershell Skript fails! RRS feed

  • Question

  • Hello Community,

    On my PC the Windows-own Backup Tool is making a FileBackup and Systemimage.
    It's too bad that this Tool isnt deleting the Filebackups automatically when the HDD runs full. So i want to delete it automatically with a Powershell Script. I know that there are several other ways to do this, but i want to do this with Powershell.

    The System and Data i want to Backup lies on a intern HDD "C:". It will be backed up on an external HDD with 1TB "I:".

    I put a few Test-Backups on the external HDD to test my Skript, but when i run it, they are'nt deleted. When i put some Datatrash on the Disk they are succesfully deleted. Why not the Test-Backups?

    Here the Script:

    --------------------------------------------------------------------------------------------------
    $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
    $princ = New-Object System.Security.Principal.WindowsPrincipal($identity)
    if(!$princ.IsInRole( `
        [System.Security.Principal.WindowsBuiltInRole]::Administrator))
         {
        $powershell = [System.Diagnostics.Process]::GetCurrentProcess()
        $psi = New-Object System.Diagnostics.ProcessStartInfo $powerShell.Path
        $script = $MyInvocation.MyCommand.Path
        $prm = $script
       foreach($a in $args) {
         $prm += ' ' + $a
       }
       $psi.Arguments = $prm
       $psi.Verb = "runas"
       [System.Diagnostics.Process]::Start($psi) | Out-Null
       return;
     }


    echo Beginne
    Start-Sleep -s 5

    $now = get-date
    dir "I:\" | where {$_.LastWriteTime -le $now.AddHours(-0)} | del -recurse -force

    Start-Sleep -s 7
    --------------------------------------------------------------------------------------------------

    I hope someone knows what to do,

    Yours faithfully,

    ToniLovesHisPrivacy


    Tuesday, February 19, 2013 1:38 PM

Answers

All replies