Powershell is just interesting. As and more I explore, I find many more possibilities with powershell. Recently was wowing when I learned that Unix commands can be brought in to Powershell by creating “Alias” commands.
Let us see some basic Powershell command-lets (cmdlets) related to Content database.
- New-SPConfigurationDatabase
- Connect-SPConfigurationDatabase
- Disconnect-SPConfigurationDatabase
- Remove-SPConfigurationDatabase
New-SPConfigurationDatabase
This cmdlet is used to create a new configuration database aka the SharePoint Farm which can be connected to the existing farm using the next Connect-SPConfigurationDatabase cmdlet.
Syntax:
New-SPConfigurationDatabase [-DatabaseName] [-DatabaseServer] [[-DirectoryDomain] ] [[-DirectoryOrganizationUnit] ] [[-AdministrationContentDatabaseName] ] [[-DatabaseCredentials] ] [-FarmCredentials] [-Passphrase] [-AssignmentCollection ]
There is a script given in technet which helps to create a complete new SP Farm. Tweak it a bit with your credentials and it is good to go
Create a new SharePoint Farm
Connect-SPConfigurationDatabase
This cmdlet is used to connect the current server to the specified configuration database. In other terms, we are configuring an existing database for the SharePoint server.
Syntax:
Connect-SPConfigurationDatabase [-DatabaseName] [-Passphrase] -DatabaseServer [-AssignmentCollection ] [-DatabaseCredentials ]
Again this is another helping script to attach a newly created SP Farm to the existing Farm. Tweak it a bit according to your credentials.
Join an existing Farm
Disconnect-SPConfigurationDatabase
As you can connect a new SharePoint farm to the existing farm, you can disconnect a SP Farm from an existing farm using Powershell. The Configuration Database must be removed before the Database can be removed. This command is only to remove and not to delete the Farm.
Syntax:
Disconnect-SPConfigurationDatabase [-AssignmentCollection ] [-Confirm []] [-WhatIf []]
Remove-SPConfigurationDatabase
To permanently delete the Configuration database the below cmdlet must be used. Before we try to delete the database, we should and must dismount the database by using the previous command.
Syntax:
Remove-SPConfigurationDatabase [-AssignmentCollection ] [-Confirm []] [-WhatIf []]
(Ref: Technet Site)