Feb 26 2019 12:54 PM
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}'
}
Feb 26 2019 01:15 PM
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
Feb 26 2019 01:20 PM
Feb 26 2019 01:27 PM
Feb 27 2019 10:25 AM
@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?
Feb 27 2019 10:27 AM
Feb 27 2019 10:30 AM
try to add
Add-PSSnapin Microsoft.Sharepoint.Powershell
in Invoke-Parallel.ps1 too.
Cheers,
Federico
Feb 27 2019 10:45 AM
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
Feb 27 2019 10:51 AM
Feb 27 2019 11:00 AM
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
Feb 27 2019 11:03 AM
Feb 27 2019 11:04 AM