Hi,
Not sure whether this is the forum to ask.I have a list of servers names and i need to get the instance names in below format.
SERVERNAME\INSTANCE1
The o/p of the script actually shows Servername,MSSQL$Instance name..Anyway to tweak this to SERVERNAME\INSTANCE1?
$servers = get-content "C:\SQLCheck\machinelist.txt" $logfile = "C:\SQLCheck\sql-instances.txt" $logerrs = "C:\SQLCheck\sql-failures.txt" Echo "Server, Instance" >> $logfile ForEach ($server in $servers) { $instances = Get-WmiObject -ComputerName $server win32_service | where {$_.name -like "MSSQL*"} if (!$?) { Echo "$server - No SQL instance found" >> $logerrs Echo "$server - No SQL instance found" } Else { ForEach ($instance in $instances) { if (($instance.name -eq "MSSQLSERVER") -or ($instance.name -like "MSSQL$*")) { Echo "$server\$instance.name" >> $logfile Echo "$server, $($instance.name)" } } } }
Best Regards, Arun http://whynotsql.blogspot.com/