====== Vrac de scripts Powershell ====== {{ :wiki:windows:scripting:powershell.png?400 |}} Cette petite fiche regroupe en vrac plusieurs scripts Powershell utile. # Sauvegarde d'une BDD d'un serveur SQL Express ```powershell $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 ```