SharePoint 2016- "Set-ContentDatabase" Not Working Using Pipe Line

In SharePoint 2016, if you try to change the settings of Content Database via PowerShell while using the Pipeline feature in your command, it throws an error.

Here, we are trying to set the content database max site count to 5 and warning site count to 4. We use the following command.

  1. Get-SPContentDatabase "WSS_content" | Set-SPContentDatabase -MaxSiteCount 5 -WarningSiteCount 4   

  1. PS C:\Users\kfinst> Get-SPContentDatabase "WSS_content" | Set-SPContentDatabase  
  2. -MaxSiteCount 5 -WarningSiteCount 4   

Here is the error we get.

"Set-SPContentDatabase - Could not connect to SPContentDatabase Name=WSS_Content using integrated security - Cannot connect to database master at SQL server at SPContentDatabase Name=WSS_Content. The database might not exist, or the current user does not have permission to connect to it. "
  1. At line:1 char:39  
  2.   
  3. + Get-SPContentDatabase "WSS_content" | Set-SPContentDatabase -MaxSiteCount 5  
  4.   
  5. -War ...  
  6.   
  7. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  8.   
  9. + CategoryInfo : InvalidData: (Microsoft.Share...ContentDatabase:  
  10.   
  11. SPCmdletSetContentDatabase) [Set-SPContentDatabase], SPException  
  12.   
  13. + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletSetConte  
  14.   
  15. ntDatabase  
  16.   
  17. PS C:\Users\kfinst>  


No matter what method we use in the pipe, it is not working at all.

  1. Get-SPContentDatabase " 12345678-90ab-cdef-1234-567890abcdef" | Set-SPContentDatabase -MaxSiteCount 5 -WarningSiteCount 4   

Or

  1. Get-SPContentDatabase -webapplciation "http://team.krossfarm.com | Set-SPContentDatabase -MaxSiteCount 5 -WarningSiteCount 4   

And, all the time, we get the same error.

"Set-SPContentDatabase : Could not connect to SPContentDatabase Name=WSS_Content using integrated security: Cannot connect to database master at SQL server at SPContentDatabase Name=WSS_Content. The database might not exist, or the current user does not have permission to connect to it."

Resolution

This is a bug in the command and already reported to Microsoft. Microsoft is currently working on this and hopefully, it will be fixed in future updates. We will update this as soon as Microsoft released the fix. In SharePoint 2010/2013, it is working fine.

Workaround

Currently, there are two workarounds for such situation. You can use PowerShell without using the pipe option in command, or use the Central Admin and change the settings of the Content Database.

PowerShell

In order to change the settings of the Content Database, don't use the pipe line.

  1. Set-SPContentDatabase –identity "WSS_Content" -MaxSiteCount 5 -WarningSiteCount 4   

To confirm the settings, please run the below command.

  1. $db = Get-SPContentDatabase "WSS_Content"$db.MaxSiteCount$db.WarningSiteCount   

Central Admin

Another method is to use the Central Admin and change the settings of Content Database. Please follow the below steps to change the settings.

  • Log on to Central Admin Site with Farm Admin account.
  • Go to Application Management >> Manage Content Database.
  • On this page, select the correct Web Application.
  • Click on the name of Content Database (it will be hyperlink).
  • On this page, you can then change the required settings (Status, Remove Content Database, Maximum Site Count, Warning Site Count, preferred Timer Job Server).

Applies to

This applies only to SharePoint Server 2016 (January 2017 Updates).