In this blog, we will learn how to deal with SPContentDatabase command in the SharePoint Management Shell.
Normally, we have multiple commands to get the web applications, sites, and web objects. By the same token, we have commands to deal with the database from Sharepoint like Get, Create, Remove, and Move.
"Get" commands
By using the “Get” command, we can easily identify the web application's database name. Also, you can know the name of the content database that contains your particular site collection. Let’s see some examples.
To find the list of content databases associated with your web application:
- Get-SPContentDatabase –WebApplication http://spserver:portnumber
To identify my particular site collection associated database.
- Get-SPContentDatabase –Site http://spserver:portnumber/sites/sitecollection
"New" Command
To create a new content database under any web application.
- New-SPContentDatabase –Name DatabaseName –WebApplication http://spserver:port
"Move" Command
To move any particular site collection to another content database, we use this command. Once it moves, the IIS Reset is required in all WFE & APP servers.
- Move-SPSite –Identity Http://spserver:port/sites/sitecollection -DestinationDatabase “ContentDBName”
To verify the above command, you can use the Get option like Get-ContentDatabase –Site Site collection URL and it will return the result with the database name, ID, Web Application name and current site count.
Here, I have just demonstrated some limited commands but you can perform some real deeper actions using the SPContentDatabase commands.