PowerShell – Script to get SQL Server Instance Info

PowerShell script to find SQL Server Instance Information
Param ([String[]] $SQLServerList)
$Module = Get-Module | where-object {$_.Name -like ‘SQLPS’} | Select-Object Name
IF ($Module -ne “SQLPS”)
{
Import-Module SQLPS
}
foreach ($SQLServer in $SQLServerList)
{
if ([array]::indexof($SqlServerList ,$SqlServer)%2 -eq 0)
{
$C =”DarkRed”
$D = “Black”
}
ELSE
{
$C= “DarkGreen”
$D = “Yellow”
}
$a=new-object Microsoft.SQLServer.Management.Smo.Server $SQLServer
Write-Host -ForeGroundColor $C -BackGroundColor $D $SQLServer ‘Server Information’
$a.Information|Select-object Parent,Version,IsSingleUser,Processors,ComputerNamePhysicalNetBios,Product,ProductLevel,Edition,PhysicalMemory,MasterDBLogPath,MasterDBPath,RootDirectory,ErrorLogPath
}
Remove-Module SQLPS

Save the script as .ps1 file(PSSQLServerInfop.ps1)
1.To run the script, set the location to file where the file exists
Set-location c:\users\sqlwhisper\Desktop
2../PSSqlServerInfo.ps1 "ServerName\InstanceName"
You can also pass multiple servernames
./PS1SqlServerInfo.ps1 -SQLServerList ServerName1\InstanceName1,ServerName2\InstanceName2

Advertisement

One thought on “PowerShell – Script to get SQL Server Instance Info

Comments are closed.