$theDate = Get-Date -Format "yyyy-MM-dd HH-mm-ss" Copy-Item "Adopted Petz" -Destination "Backups\$theDate\Adopted Petz" -Recurse Copy-Item "PetzAProfiles" -Destination "Backups\$theDate\" -Recurse $files = @(Get-ChildItem -Path "Backups") | Sort-Object $fileCount = $files.Count $numBackupsToRetain = 10 if ($fileCount -gt $numBackupsToRetain) { for($i = 0; $i -lt $fileCount - $numBackupsToRetain; $i++) { Remove-Item ($files[$i]).fullname -Recurse } } $PetzExe = Get-ChildItem | Where-Object { $_.Name -match "Petz [1-5].exe$" } & $PetzExe.fullname