Link to home
Start Free TrialLog in
Avatar of Pavan Joshi
Pavan Joshi

asked on

Get-Service : Cannot find any service with service name 'PrintSpooler'.

I have a set of servers and in those few are external servers. When I try to get a particular services as print spooler it comes out with an error Get-Service : Cannot find any service with service name 'PrintSpooler'
Infact these servers have different credentials we use.
When I try with other servers in the list its working fine.
Please help.
Avatar of Mal Osborne
Mal Osborne
Flag of Australia image

"Printspooler" was an old name, with newer versions of Windows it has changed to just "spooler"
Here's how you can search for yourself next time.  From PowerShell:

User generated imageCapture.PNG
Avatar of Pavan Joshi
Pavan Joshi

ASKER

No actual service name is "Lotus Domino Server (FLotusDominodata)"
I just gave that as an example.
I am trying to get the service status from few external servers which has different credentials....
When I apply this script
$server = Get-Content -Path C:\Temp\servers.txt
$server | foreach { (Get-Service -Name "Lotus Domino Server (FLotusDominodata)" -computername $_) | Select-Object Status, Name, DisplayName | ft -AutoSize

I get status for other servers but not external servers...
Try this for one of the problem servers.  If it works we can tailor it to your needs:

New-CimSession -ComputerName <server hostname> -Credential (Get-Credential)
Get-CimSession -Id 1 | Get-CimInstance -ClassName win32_service | Select-Object Name,Status | Format-Table -AutoSize

Open in new window

I should have been more clear.  The <server hostname> in line 1 should be the server you can't access.
Get-Service is still available if that command is more appropriate for you, but you could have to wrap it with Invoke-Command.
$authenticatedServers = 'ext1', 'ext2'

# Assuming the same set of credentials can be used for each external server
$Credential = Get-Credential
foreach ($server in $serverList) {
    $params = @{
        ComputerName = $server
    }
    # Only use credentials for some servers
    if ($server -in $authenticatedServers) {
        $params.Credential = $Credential
    }

    Invoke-Command -ScriptBlock { Get-Service -Name "Lotus Domino Server (FLotusDominodata)" } @params
}

Open in new window

The connection will preferentially use Windows Remoting to connect, remoting will therefore need to have been configured on the remote server. Get-Service itself uses RPC so it's not guaranteed to "just work".

The same issue with remoting applies to CimSessions as used in Jason's example. New-CimSession preferentially uses Windows Remoting. However, New-CimSession can be forced to use DCOM over RPC (old-style WMI access) if you don't have remoting configured:
New-CimSession -ComputerName <server hostname> -Credential (Get-Credential) -SessionOption (New-CimSessionOption -Protocol DCOM)

Open in new window

@Chris: Let me try and get back :)
@Chris: I am getting the message as attached in the snapshot.User generated image
$serverList has no value at the moment, it needs that to get started. That can come from any number of places. It's hard-coded in the example below (now), but you could as easily read it from a text file (Get-Content), from AD, from SQL, and so on.
$serverList = 'int01', 'int02', 'int03', 'ext1', 'ext2'
$authenticatedServers = 'ext1', 'ext2'

# Assuming the same set of credentials can be used for each external server
$Credential = Get-Credential
foreach ($server in $serverList) {
    $params = @{
        ComputerName = $server
    }
    # Only use credentials for some servers
    if ($server -in $authenticatedServers) {
        $params.Credential = $Credential
    }

    Invoke-Command -ScriptBlock { Get-Service -Name "Lotus Domino Server (FLotusDominodata)" } @params
}

Open in new window

In a similar way, if you have a predictable naming convention, the $authenticatedServers list could be turned into pattern matching. For example, if they are structure as in the example you could do this:
$serverList = 'int01', 'int02', 'int03', 'ext1', 'ext2'
$authenticatedServers = 'ext*'

# Assuming the same set of credentials can be used for each external server
$Credential = Get-Credential
foreach ($server in $serverList) {
    $params = @{
        ComputerName = $server
    }
    # Only use credentials for some servers
    if ($server -like $authenticatedServers) {
        $params.Credential = $Credential
    }

    Invoke-Command -ScriptBlock { Get-Service -Name "Lotus Domino Server (FLotusDominodata)" } @params
}

Open in new window

I tried both and its not working. I also found this a standalone PC in a workgroup and not a domain.
When I tried with new ps session too its giving user name and password is incorrect...

Please help...
ASKER CERTIFIED SOLUTION
Avatar of Jason Crawford
Jason Crawford
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The above solutions have worked for me and I was able to find the services and stop them on all servers.
Sorry for late reply.