How to find the SQL instance using PowerShell and store in a variable

Posted on Posted in Scripts

Here is a PowerShell script to find the SQL server instance and store the value in a variable:

 
$InstanceName = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server").InstalledInstances
$Instance = $env:computername+'\'+$InstanceName

Write-Host "The SQl Server instance name is $Instance"

Leave a Reply

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