Home

Attach and upgrade multiple content databases in SharePoint

Highlighted
Bobby Fentress
Occasional Contributor

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

Hi @Bobby Fentress ,

I suggest you to change your approach, think about Invoke-Parallel https://gallery.technet.microsoft.com/scriptcenter/Run-Parallel-Parallel-377fd430 
this guy obteined really good results :)
Cheers,
Federico

Thanks @Federico Porceddu! I will check this out to see how Invoke-Parallel runs to see if it can help here.
Welcome :) Let me know :)

@Federico Porceddu I have reviewed this function and have tried it out in the example where the function accepts an input (Database Names in my case from a text file) and then runs a script (Mounting those DB's in another script action) but it doesn't seem to work. It seems to have a problem when I try to run the script where the mount-spcontentdatabase command is:

Get-RunspaceData : The term 'Mount-SPContentDatabase' is not recognized as the name of a cmdlet, function,script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At E:\SharePoint\Scripts\Admin\Invoke-Parallel.ps1:543 char:13

+ Get-RunspaceData -wait

 

Any ideas?

 

I know the error is from running powershell without the add-psnapin Microsoft.sharepoint.powershell add-in, but in the Mount script I put in a line for this to apply.

Hi @Bobby Fentress 

try to add 

Add-PSSnapin Microsoft.Sharepoint.Powershell

in Invoke-Parallel.ps1 too.

Cheers,

Federico

okay, I tried that and now I seem to get a different error:

Get-RunspaceData : The term 'param' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At E:\SharePoint\Scripts\Admin\Invoke-Parallel.ps1:544 char:13
+             Get-RunspaceData -wait
+             ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (param:String) [Write-Error], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Get-RunspaceData

Can you post the full script please?
Does the "single" (not parallel) script works correct?
Another way is debug script with Powershell IDE
Cheers,
Federico

Sure, here is my main script below. The Mount script and DB name file are attached. The invoke-parallel is the same except with the add-pssnapin added at the top of the script.

. "E:\SharePoint\Scripts\Admin\Invoke-Parallel.ps1"

Invoke-Parallel -ScriptFile E:\SharePoint\Scripts\Admin\MountDB.ps1 -InputObject $(Get-Content E:\Export.txt)

 

MountDB.ps1 Script:

Add-PSSnapin microsoft.sharepoint.powershell
param ($DBName)
$WebApp = "https://webapp.domain.com"
$SQLServer = "sqlserver"
Mount-SPContentDatabase -Name $DBName -WebApplication $WebApp -DatabaseServer $SQLServer

 

Export.txt

WSS_Content_1

WSS_Content_2

 

 

 

I can't see attachment :)
I couldn't attach them, so I had to paste it into my reply below the colored command
Related Conversations
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
2 Replies
Early preview of Microsoft Edge group policies
Sean Lyndersay in Discussions on
65 Replies
*Updated 9/3* Syncing in Microsoft Edge Preview Channels
Elliot Kirk in Articles on
202 Replies