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

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"
Advertisements
This entry was posted in Scripts and tagged , , . Bookmark the permalink.

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