Check SQL Server configuration with powershell


When you are working with many SQL server at once, you will minimize the validation of configuration and settings. Normally, you open “Management Studio” and run some commands in a query window or navigate through the GUI. But in newer version (even powershell 2.0) you can access most of the SQL Server configuration properties and settings by powershell commands.

The following script will connect to the currently loggin server and write typical configured properties on a server you are looking for:

Add-Type -AssemblyName "Microsoft.SqlServer.Smo, `
	Version=10.0.0.0, `
	Culture=neutral, `
	PublicKeyToken=89845dcd8080cc91"

$server = New-Object `
	Microsoft.SqlServer.Management.Smo.Server($env:ComputerName)

Write-Host "---------------------------------------------"
Write-Host "##### check_sql_config, by sveroa       #####"
Write-Host "---------------------------------------------"

Write-Host "Server         : " $env:ComputerName
Write-Host "Network name   : " $server.Properties["NetName"].Value
Write-Host "Product        : " $server.Properties["Product"].Value
Write-Host "VersionString  : " $server.Properties["VersionString"].Value
Write-Host "Edition        : " $server.Properties["Edition"].Value;
Write-Host "ProductLevel   : " $server.Properties["ProductLevel"].Value
Write-Host "Processors     : " $server.Properties["Processors"].Value;
Write-Host "PhysicalMemory : " $server.Properties["PhysicalMemory"].Value;
Write-Host "Max Memory     : " $server.Configuration.MaxServerMemory.ConfigValue;
Write-Host "Data folder    : " $server.Properties["DefaultFile"].Value;
Write-Host "Log folder     : " $server.Properties["DefaultLog"].Value;
Write-Host "Backup folder  : " $server.Properties["BackupDirectory"].Value;
Write-Host "Collation      : " $server.Properties["Collation"].Value;

You can also run this script on a remote SQL server by some changes described in this blog.

Happy coding…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s