Powershell and SQL Server – Server-Property – Edition-Version

The script loops through each of the sql instance and pulls SERVERPROPERTY information such as Version,Productversion,ProductLevel,Edition

cls

if (-not (Get-Module SQLPS)) 
    {Import-Module SQLPS} 

#Get list of server from text files

$SQLserverDB=@() 
$SQLserverDB=Get-Content "C:\PowershellScript\ServerList.txt"

    foreach($SqlServer in $SQLserverDB)
    {

        $result=Invoke-Sqlcmd -ServerInstance $SqlServer  -Database master -Query "SELECT SERVERPROPERTY('ServerName') ServerName,substring(@@version,0,charindex('-',@@version)) Version, SERVERPROPERTY('productversion') Productversion, SERVERPROPERTY('productlevel') Productlevel, 
SERVERPROPERTY('edition')EngineEdition" -QueryTimeout 0
 
       $result |SELECT ServerName,Version,Productversion,Productlevel,EngineEdition |ft
       }

ServerProperty1

Leave a Reply

Your email address will not be published. Required fields are marked *