25 Apr

Bulk restore bacpac files local

sqlserver_logo
 
It is easy to import a bacpac file via the SQL Server Management Studio. Now it is a hard time if you have to import a whole bunch of bacpac files.
 
This can easily be solved by using PowerShell and a small script.


 
 

This data you’ll be needing for this script:

  • Folder where the scripts are located: [FOLDERPATH]
  • The name of your local SQL-server: [SERVERNAME]


cd [FOLDERPATH]
$goodlist = dir
cd 'C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin'
foreach($i in $goodlist){ $name = $i.Name; $namer = $i.Name.Substring(0, $i.Name.length - 7); .\SqlPackage.exe /a:Import /sf:[FOLDERPATH]\$name /tdn:$namer /tsn:[SERVERNAME]}

Keep in mind that my bacpac-files are saved as followed: [databasename].bacpac

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.