This is based on code from Mike Galvin. When you copy the dirs to a network drive or so, this allows you to delete older backups.
Create a file called “Remove-old-Backups.ps1” and enter the following code:
##Remove previous backup folders older than the configured number of days.
$Backup = "\\NETWORKDRIVE\FOLDER\"
$History = 4
## Location of the VM names file
$VmList = "c:\scripts\vms.txt"
##If a VM list file is configured, get the content of the file.
$Vms = Get-Content $VmList
ForEach ($Vm in $Vms)
Get-ChildItem -Path $Backup -Filter "$Vm
-Directory | Where-Object CreationTime –lt (Get-Date).AddDays(-$History) | Remove-Item -Recurse -Force