How can the System databases in SQL Server 2016 be moved using Powershell?
2
votes
3
answers
1344
views
I'm trying to move the system databases using Powershell ie. **without** using any T-SQL.
1. Using SMO :
`Install-Module SQL-SMO
$smo = New-SMO -ServerName localhost
$smo.databases["TempDB"].PrimaryFilePath= "F:\Tempdb\"
$smo.databases["TempDB"].Alter()` gives an error:
>'PrimaryFilePath' is a ReadOnly property.
The logfile moves fine though.
$smo.databases["TempDB"].LogFiles.Filename = "F:\Tempdb\tempdb.ldf"
2. Couldn't locate any specific cmdlets in the SQLServer or DBATools modules either. Copy-DbaDatabase
comes closest; but not exactly.
Asked by Ayan Mullick
(115 rep)
May 8, 2018, 10:16 PM
Last activity: May 12, 2018, 12:09 AM
Last activity: May 12, 2018, 12:09 AM