Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joerodgers/87b19a98c1b3061843ce42fe2a5a1595 to your computer and use it in GitHub Desktop.
Save joerodgers/87b19a98c1b3061843ce42fe2a5a1595 to your computer and use it in GitHub Desktop.
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell
$timestamp = Get-Date -Format FileDateTime
# Using Get-SPWebApplication here b/c Get-SPContentDatabase does not return databases that are not "online"
Get-SPWebApplication | SELECT -ExpandProperty ContentDatabases | SELECT @{ Name="WebApplicationUrl"; Expression={ $_.WebApplication.Url }}, Name, Server, WarningSiteCount, MaximumSiteCount, Status | Export-Csv "E:\_temp\DatabaseMappings_$timestamp.csv" -NoTypeInformation
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell
$rows = Import-Csv -Path "E:\_temp\DatabaseMappings_20210624T1145590703.csv"
foreach( $row in $rows )
{
if( Get-SPContentDatabase -Identity $row.Name -ErrorAction SilentlyContinue )
{
Write-Warning -Message "A content database with the name '$($row.Name)' is already mounted to this farm."
continue
}
Mount-SPContentDatabase `
-WebApplication $row.WebApplicationUrl `
-Name $row.Name `
-DatabaseServer $row.Server `
-WarningSiteCount $row.WarningSiteCount `
-MaxSiteCount $row.MaximumSiteCount
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment