Thanks for your response.
My query is:
$instanceNameList = Get-Content "C:\Powershell\serverlist.txt"
$results = @()
foreach($instanceName in $instanceNameList)
{
$results += Invoke-Sqlcmd `
-Query "select SERVERPROPERTY('ServerName') as Server, count(*) as 'DB Count' from sys.databases" `
-ServerInstance $instanceName
}
# print results
$results | Format-Table -autosize
Also, I have the below environment path setup in my system:
%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules
Error Message:
The term 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:6 char:34
+ $results += Invoke-Sqlcmd <<<< `
+ CategoryInfo : ObjectNotFound: (Invoke-Sqlcmd:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Thanks.