Powershell Script to restore bunch of SQL databases

Posted on 9/8/2013 @ 11:20 AM in #Vanilla .NET by | Feedback | 1918 views

Self descriptive title,

   1:  $path = (get-location).path
   2:  $files = get-childitem | where {$_.extension -eq ".bak"}
   3:  foreach($file in $files)
   4:  {
   5:      $dbPath = $path + '\' + $file
   6:      $dbName = $file.ToString().Replace(".bak", "")
   7:      write-host "Adding" $dbPath "to db " $dbName
   8:      Restore-SqlDatabase -ServerInstance "writeyourserverinstancehere" -Database $dbName -BackupFile $dbPath
   9:  }

Sound off but keep it civil:

Older comments..