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


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:

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?

  • In your loop examine $server. See what its type is and properties are. It's probably not something that can be passed directly to the -computername argument of get-service. – David Browne - Microsoft Jan 15 '18 at 23:10

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


Have you tried Microsoft's Assessment and Planning Toolkit (MAP).


You will need to adjust your script to call out the property returned by the AD command.

So the following adjustment should work:

...get-service -computername $server.Name...

This will pass in the string value of the device name.


If you're using PowerShell v2, you've got to enable the remoting service on every host computer.

Related Reading: Running Remote Commands - Microsoft Technet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.