How to get information about all SQL Server instances on a local server (PowerShell)
Introduction
This PowerShell script will demo how to get information about all the SQL Server instances on a local server.
Scenarios
As many people ask how to get information about instances, this script will list all the information about instances on a local server.
Script
You can use this script in this way:
1. Run Microsoft PowerShell as Administrator
2. Run the script in the form: &Path
For example: &"E:\OneScript\Upload\Julie\GetAllInstances.ps1"
3. Press Enter and wait for the results. After the script finishes running, we抣l get the following figure:
Here are some code snippet for your reference:
PowerShellEdit|Removepowershell[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null Write-Host "-------------------------------" Write-Host "This is $instance" Write-Host "-------------------------------" $instanceinfo = New-Object -typeName Microsoft.SqlServer.Management.Smo.Server($instance) $instanceinfo[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null Write-Host "-------------------------------" Write-Host "This is $instance" Write-Host "-------------------------------" $instanceinfo = New-Object -typeName Microsoft.SqlServer.Management.Smo.Server($instance) $instanceinfo
Prerequisites
SQL Server 2005 /SQL Server 2008/SQL Server 2012
Microsoft All-In-One Script Framework is an automation script sample library for IT Professionals. The key value that All-In-One Script Framework is trying to deliver is Scenario-Focused Script Samples driven by IT Pros' real-world pains and needs. The team is monitoring all TechNet forums, IT Pros' support calls to Microsoft, and script requests submitted to TechNet Script Repository. We collect frequently asked IT scenarios, and create script samples to automate the tasks and save some time for IT Pros. The team of All-In-One Script Framework sincerely hope that these customer-driven automation script samples can help our IT community in this script-centric move.