Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Basics - Monitor SQL Server database Auto Create Statistics
# Code answers from Session Q & A (
$sqlservers = "sqlserver2014a","sql2012-esx"
foreach ($sqlserver in $sqlservers) {
Write-Output "Connecting to $sqlserver"
$server = New-Object Microsoft.SqlServer.Management.Smo.Server $sqlserver
foreach ($db in $server.databases) {
if ($db.AutoCreateStatisticsEnabled -eq $false) {
# Set it back? Not sure what you're looking to do.
$db.AutoCreateStatisticsEnabled = $true
# Or just write a warning?
Write-Warning "$($ has the wrong setting. I have no idea who changed it, though."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.