PowerShell to get all servers with SQL Server or Oracle installed Overview:

Trying to get all servers with SQL Server or Oracle installed.

Troubleshooting:

get-service -computername "" works fine when run by itself.

But when used in script block of Foreach statement it results in this error:


  Get-Service : Cannot open Service Control Manager on computer
  '@{Name=}'. This operation might require other privileges.


Code Used:

CLS
Import-Module ActiveDirectory

$servers = Get-ADComputer -Filter {OperatingSystem -like "*Server*"} -Property Name | Select Name 

Foreach ($server in $servers)
{
    get-service -computername $server |where{$_.name -like "OracleService*" -or $_.name -like "*SQL*"}| select @{N='Sever';E={$_.name}}, Name, DisplayName | Format-Table -A
}


What to do?
This is an easy way to find the SQL Servers with the dbatools module. 

Install-Module dbatools    
Find-DbaInstance -DiscoveryType All


Reference: 
https://docs.dbatools.io/#Find-DbaInstance