Category Archives: PowerShell
Powershell Mount and dismount content database
While working on the scripts for dismounting all content database for a DR situation found SPContentdatabase do not display OFFLINE databases. So had to work around to get the offline content database for each web application and disable it.
Code
Puts OFFLINE AND DISMOUNT all attached DBs
get-spwebapplication -identity webappURL | foreach {$SPContentDB = $_.ContentDatabases}
$SPContentDB | ForEach {Set-SPContentDatabase -Identity $_ -status disabled}
$SPContentDB | ForEach {Dismount-SPContentDatabase $_ -confirm:$false}
Found another interesting blog where it mentioned putting SharePoint content database offline is no the best practice rather putting the sitecollection max count to current number of sitecollections also avoids creating new sitecollection for the specified content database.
MOUNT DATABASE
mount-spcontentdatabase “DBName” -DatabaseServer “DBServer” -Webapplication webappURL