Get all content databases and set the warning & maximum number of sites

Hello SharePoint PowerShell experts.  I need help with a script, and I will admit, I'm really NOT good at arrays.

We have multiple (25 content DBs to be exact) for one web app that have the out of the box 2000/5000 for warning and maximum # of sites.  I can get all the content DBs and I tried to SET them but it only sets one Content DB.  Here's what I mean:

This script gets me ALL of the content DBs:

Get-SPContentDatabase | %{Write-Output "$($_.Name)”;} 

I also tried this:

 $db = Get-SPContentDatabase | %{Write-Output "- $($_.Name)”; foreach($site in $_.sites){write-Output $site.url}}

$db.MaximumSiteCount = 200

$db.WarningSiteCount = 100



That just updated the very first content db but not all of them.  Can someone help?

No Data
  • Got it!  Thank you for your help!!!

    $webapp = ""
    $maxsite = "200"
    $warnsite = "100"


    #Add the SharePoint PowerShell Snap-In
    add-pssnapin microsoft.sharepoint.powershell -EA 0

    ForEach($db in (Get-SPContentDatabase -webapplication $webapp)){

        Set-SPContentDatabase -Identity $db -MaxSiteCount $maxsite -WarningSiteCount $warnsite

No Data