$dt = Get-Date -Format ddMMyyyyHHmmss $dbname = 'orchard' $username = 'orchard' $dir = 'B:\BDD' $bakfile = "$dir\orchard_$($dt).bak" $limit = (Get-Date).AddMinutes(-30) $Extension = "*.bak" Get-ChildItem -Path $dir -Filter $Extension -Force | Where-Object {$_.CreationTime -lt $limit} | Remove-Item Write-Output "backup database to disk file = $bakfile" Backup-SqlDatabase -ServerInstance VADE-AD1\SQLExpress -Database $dbname -BackupFile $bakfile