Forum Discussion

bjfentress's avatar
bjfentress
Copper Contributor
Feb 26, 2019

Attach and upgrade multiple content databases in SharePoint

Hello everyone,

 

I am working on a script right now to try and speed up the rate at which we attach content databases to a new SharePoint farm to cut down on our upgrade time when moving to SharePoint 2016. I started to create a script to launch a new window when trying to attach a database from a list of DB names in a text file, but when I try to run it I get a new PowerShell window with a bunch of unreadable text in it and its impossible to understand. Can anyone point me in the right direction on sending these variables to a new window in PowerShell? Example code is below.

Thanks -BJ

Add-PSSnapin microsoft.sharepoint.powershell
#Input DB Names from an extracted file from Prod or somewhere else named C:\Export.txt
$Names = Get-Content -Path E:\Export.txt
$WebApp = Get-SpWebApplication -identity https://webapp.domain.com
$SQLServer = "sqlserver"
foreach ($name in $Names){
invoke-expression 'cmd /c start powershell -Command { add-pssnapin microsoft.sharepoint.powershell; Mount-SPContentDatabase -Name $name -Webapplication $Webapp}'
}

11 Replies

Resources