About Me

My photo
I am MCSE in Data Management and Analytics with specialization in MS SQL Server and MCP in Azure. I have over 13+ years of experience in IT industry with expertise in data management, Azure Cloud, Data-Canter Migration, Infrastructure Architecture planning and Virtualization and automation. Contact me if you are looking for any sort of guidance in getting your Infrastructure provisioning automated through Terraform. I sometime write for a place to store my own experiences for future search and read by own blog but can hopefully help others along the way. Thanks.

How to Retrieve MSSQLSERVER or SQL Server engine running on a set of Servers.

How to Retrieve MSSQLSERVER  or SQL Server engine running on a set of Servers.





Create a Notepad file and add all server name

Save the file in C:\Temp Folder


.\Get-SQLServer.ps1 -ComputerList "Computer.txt"

Save the powershell script with name "Get-SQLServer.ps1" in C:\Temp folder.

#Requires -Version 2.0

param
(
[Parameter(Position=0,ValuefromPipeline=$true)][string][alias("cn")]$computer,
[Parameter(Position=1,ValuefromPipeline=$false)][string]$computerlist
)

If (-not ($computer -or $computerlist))
{
$computers = $Env:COMPUTERNAME
}

If ($computer)
{
$computers = $computer
}

If ($computerlist)
{
$computers = Get-Content $computerlist
}

foreach ($computer in $computers)
{
$object = Get-WmiObject win32_service -ComputerName $computer  | where {($_.name -like "MSSQL$*" -or $_.name -like "MSSQLSERVER" -or $_.name -like "SQL Server (*") -and $_.name -notlike "*helper*" -and $_.name -notlike "*Launcher*"}
if ($object)
{
write-host "####################Retrieving Details for Computer:  $computer" -ForegroundColor Green
$instInfo= $object | select Name,StartMode,State, Status
$instInfo
}else
{
 Write-Host "No instance found!"
 }
}

No comments: