PowerShell makes it easy to query a SQL Server instance and export current configurations. We can make use of the SMO server object and query all the properties. The following is an example script that performs this export:
#current server name $servername = "ROGUE" $server = New-Object "Microsoft.SqlServer.Management.Smo.Server" $servername $server | Get-Member | Where-Object Name -ne "SystemMessages" | Where-Object MemberType -eq "Property" | Select-Object Name, @{Name="Value";Expression={$server.($_.Name)}} | Format-Table -AutoSize
Once the script runs, you should find all the instance properties and corresponding values displayed on your screen:
Let's walk through the script. The preceding sample script creates an SMO server object based on the SQL Server instance named ROGUE
:
#current server name $servername = "ROGUE" #or localhost $server = New-Object "Microsoft.SqlServer.Management.Smo.Server" $servername