1

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?

1
  • 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. Jan 15, 2018 at 23:10

4 Answers 4

3

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

1
  • Maybe but Assessment and Planning Toolkit (MAP) provides WCI, Register and SQL Login. This means that it can also find SQL Server instances that are offline or on crazy ports. May 20, 2021 at 10:14
1

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

0

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.

0

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 and acknowledge you have read our privacy policy.

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