Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

SQL Powershell Script To Restore multiple databases at One Go

By Raushan,

#  This script is used ONLY in test/development environments!
#  If you are planning to use this to restore production databases you should first test and evaluate the script in a test environment.
#  You can change the script if needed to match your environment and needs.
 
# Script will restore all the databases (*.bak) which are located in the folder defined as parameter.
# It will place database files to location defined for data and log files in SQL Server instance settings

# Steps to run this script:

1)First Save the script in file "D:\PSScriptToRestoreDatabases.PS1" -- you can save it at any location and write the command accordingly.
2)Open Run-->sqlps
3)write below commands .. Specify the BackupFileLocation and SQLServerInstance in this command
   D:\PSScriptToRestoreDatabases.PS1 -BackupFileLocation [bak_file_location] -SqlServerName [SQL Server Instance]

Parameters:
   -BackupFileLocation parameter is the full path to the folder where the BAK files are located
   -SqlServerName parameter is the SQL Server instance name where to restore

#  Example:
#  D:\PSScriptToRestoreDatabases.PS1   -BackupFileLocation "D:\SQLBackups" -SqlServerName "DEFAULT"
#  D:\PSScriptToRestoreDatabases.PS1   –BackupFileLocation “D:\DBBackups” –SqlServerName “.\SQL2008R2”
#  D:\PSScriptToRestoreDatabases.PS1   –BackupFileLocation “D:\DBBackups” –SqlServerName “.\SQL2012”

You will get the results like below ...

Total article views: 1455 | Views in the last 30 days: 15
 
Related Articles
FORUM

Backup location

Backup location

SCRIPT

Script move of DB files from one location to another

Generates Scripts to move DB files from one location to another SQL and powershell scripts

FORUM

Index Location?

Index Location?

FORUM

Database Default file Locations

Database Default Locations in Database Setting Under Server Properties

FORUM

default data/log file location

query to get default data/log location

Tags
powershell    
 
Contribute