function Remove-VMBackup {
    Remove old backup files.

    Choose how long you want to keep a backup of your VMs. This cmdlet looks
    at the age of the files in the folder specefied and deletes them if they are
    older than the set in the Retention parameter.

    .PARAMETER Destination
    Specify the location of the stored backups.

    .PARAMETER Retention
    Configure how long you want to keep the backups. Default is 30 days.

    .PARAMETER Force
    The Force parameter allows the user to skip the "Should Continue" box.

    Remove-VMBackup -Destination 'D:\Backup\Hyper-V' -Retention 21

    Removes any files older than 21 days in the directory D:\Backup\Hyper-V

    Author: Frederik Hjorslev Poulsen


    [CmdletBinding(SupportsShouldProcess = $true,
        ConfirmImpact = 'Medium')]
    param (

        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true)]

        [Parameter(Mandatory = $false)]
        [int]$Retention = 30,

        [Parameter(Mandatory = $false)]

    process {
        $OldBackups = Get-ChildItem -Path $Destination -Recurse -Force | Where-Object -FilterScript { (((Get-Date)-$_.LastWriteTime) -gt (New-TimeSpan -Day $Retention)) }
        $RemoveOldSCMessage = @"
Do you want to remove any backups or files stored in $($Destination) older than $($Retention) days?

        if ($null -ne $OldBackups) {
            if ($Force -or $PSCmdlet.ShouldContinue($RemoveOldSCMessage, 'Remove old backups?')) {
                foreach ($OldBackup in $OldBackups) {
                    Write-Verbose -Message "Deleteing $($OldBackup) because it is older than $($Retention)."

                $OldBackups | Remove-Item -Recurse -Force
    } # Process
} # Cmdlet