Created
June 24, 2021 15:59
-
-
Save joerodgers/87b19a98c1b3061843ce42fe2a5a1595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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