Get SQL Server configuration, service info, start type along with enabled Trace Flags of local or remote servers.
This script outputs sql server configuration, service, start type, Service Account along with startup trace flags. The script will work on SQL Server 2005 and up.
function Get-SQLAndGlobalTraceFlagsDetails { <# .SYNOPSIS Returns SQL Server Configuration, Service and global TraceFlag details .DESCRIPTION Get-SQLAndGlobalTraceFlagsDetails is a function that returns server high level server configuration information for one or more Microsoft SQL Server .PARAMETER ComputerName The computer that is running Microsoft SQL Server that you’re targeting .EXAMPLE Get-SQLAndGlobalTraceFlagsDetails -ComputerName sql01 .EXAMPLE Get-SQLAndGlobalTraceFlagsDetails -ComputerName HQDBSP18 .EXAMPLE "hqdbst03","hqdbsp16" | % { Get-SQLAndGlobalTraceFlagsDetails -ServerName $_ } .EXAMPLE ForEach ($server in Get-ChildItem C:\server.txt) { Get-SQLAndGlobalTraceFlagsDetails -ServerName $server } .INPUTS String .OUTPUTS PSCustomObject , console or CSV #> [CmdletBinding()] param ( [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] [Alias('ServerName','PSComputerName','ComputerName')] [string[]]$Ser ) # Used to store the result $Results = @() # The below array used to concatenate the Trace flag details $TraceFlag=@() #create an smo object for the SQL Server [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")|out-null $SQLServer = new-object ('Microsoft.SQLServer.Management.Smo.Server') $Ser $SQL= $SQLServer | select Name, Edition, BuildNumber, Product, ProductLevel, Version, Processors, PhysicalMemory, DefaultFile, DefaultLog, MasterDBPath, MasterDBLogPath, BackupDirectory, ServiceAccount,ServiceStartMode,State $SQLServer.EnumActiveGlobalTraceFlags()|%{ [string]$b=$_.status [string]$c=$_.TraceFlag $TraceFlag+=$c.ToString() +'->'+ $b.ToString() } $Properties = @{ Name = $SQL.name Edition = $SQL.Edition BuildNumber = $SQL.BuildNumber Product=$SQL.Product ProductLevel=$SQL.ProductLevel Version=$SQL.Version Processors=$SQL.Processors DefaultLog=$SQL.DefaultLog MasterDBPath=$SQL.MasterDBPath MasterDBLogPath=$SQL.MasterDBLogPath BackupDirectory=$SQL.BackupDirectory ServiceAccount=$SQL.ServiceAccount StartupMode=$SQL.ServiceStartMode State=$SQL.State TraceAndStatus=($TraceFlag -join ',')} $Results += New-Object psobject -Property $properties $Results | Select-Object Name, Edition, BuildNumber,TraceAndStatus,Product,ProductLevel,Version,Processors,DefaultLog,MasterDBPath,MasterDBLogPath,BackupDirectory,ServiceAccount,StartupMode,State } "hqdbst03","hqdbsp16" | % { Get-SQLAndGlobalTraceFlagsDetails1 -ServerName $_ }