Get-Service from Remote server returns wrong service list ?

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
ITEngineer
Posts: 210
Joined: Wed Oct 12, 2011 10:52 am

Get-Service from Remote server returns wrong service list ?

Post by ITEngineer »

I wonder how to get the specific services based on the exact specific service name listed on the array of strings on a remote server?

These are the below services I wanted to check:

Code: Select all

Status   Name               DisplayName                           
------   ----               -----------                           
Running  DFS                DFS Namespace                         
Running  DFSR               DFS Replication                       
Running  DNS                DNS Server                            
Running  EventSystem        COM+ Event System                     
Running  IsmServ            Intersite Messaging                   
Running  KDC                Kerberos Key Distribution Center      
Running  LANMANServer       Server                                
Running  LANMANWorkstation  Workstation                           
Running  Netlogon           NETLOGON                              
Running  NTDS               Active Directory Domain Services      
Running  RPCSs              Remote Procedure Call (RPC)           
Running  SAMSs              Security Accounts Manager             
Running  W32Time            Windows Time
However, the below script returns the wrong services from the supplied name from $ServiceList variable.

The script I have so far:

Code: Select all

$ServiceList = @(
    'DFS'
    'DFSR'
    'DNS'
    'EventSystem'
    'IsmServ'
    'KDC'
    'LANMANServer'
    'LANMANWorkstation'
    'NETLOGON'
    'NTDS'
    'RPCSs'
    'SAMSs'
    'W32Time'
)

$input = Get-ADDomainController -Filter * | Select-Object -ExpandProperty HostName
$input | ForEach-Object {
    $Servers = ($_ -split '\.')[0]
    $Servers | ForEach-Object `
    {
        $Server = $_
Get-Service -ServiceName $ServiceToCheck -ComputerName $Server)
                    {
                        $services | Select-Object -ExpandProperty ServicesDependedOn | Select-Object StartType, Status, Name, DisplayName, Machinename, @{ N = 'Service Dependency'; E = { (Get-Service -Name $_.ServicesDependedOn -ComputerName $Server | ForEach-Object { "$($_.Name): $($_.Status)" }) -join '; ' } }                  
} | Out-GridView
The Calculated Property:
@{ N = 'Service Dependency'; E = { (Get-Service -Name $_.ServicesDependedOn -ComputerName $Server | ForEach-Object { "$($_.Name): $($_.Status)" }) -join '; ' } }
Also not showing at all (blank) instead of service1: running; serviceN:stopped...

Thank you in advance.
Last edited by ITEngineer on Wed Sep 23, 2020 5:50 pm, edited 1 time in total.
/* IT Engineer */

jvierra
Posts: 14691
Joined: Tue May 22, 2007 9:57 am
Answers: 7
Has voted: 2 times
Been upvoted: 5 times

Re: Get-Service from Remote server returns wrong service list ?

Post by jvierra »

Unfortunately your question is not answerable with the information provided.

To get a list of services just ask for the list.
Get-Service $listOfServices

help get-service -Parameter Name

User avatar
ITEngineer
Posts: 210
Joined: Wed Oct 12, 2011 10:52 am

Re: Get-Service from Remote server returns wrong service list ?

Post by ITEngineer »

jvierra wrote:
Wed Sep 23, 2020 7:58 am
Unfortunately your question is not answerable with the information provided.

To get a list of services just ask for the list.
Get-Service $listOfServices

help get-service -Parameter Name
That's good, thank you for the response. 8-)
/* IT Engineer */

Anayazius
Posts: 11
Joined: Tue Jun 23, 2020 5:04 am

Re: Get-Service from Remote server returns wrong service list ?

Post by Anayazius »

ITEngineer wrote:
Wed Sep 23, 2020 5:00 am
I wonder how to get the specific services based on the exact specific service name listed on the array of strings on a remote server?

These are the below services I wanted to check:

Code: Select all

Status   Name               DisplayName                           
------   ----               -----------                           
Running  DFS                DFS Namespace                         
Running  DFSR               DFS Replication                       
Running  DNS                DNS Server                            
Running  EventSystem        COM+ Event System                     
Running  IsmServ            Intersite Messaging                   
Running  KDC                Kerberos Key Distribution Center      
Running  LANMANServer       Server                                
Running  LANMANWorkstation  Workstation                           
Running  Netlogon           NETLOGON                              
Running  NTDS               Active Directory Domain Services      
Running  RPCSs              Remote Procedure Call (RPC)           
Running  SAMSs              Security Accounts Manager             
Running  W32Time            Windows Time
However, the below script returns the wrong services from the supplied name from $ServiceList variable.

The script I have so far:

Code: Select all

$ServiceList = @(
    'DFS'
    'DFSR'
    'DNS'
    'EventSystem'
    'IsmServ'
    'KDC'
    'LANMANServer'
    'LANMANWorkstation'
    'NETLOGON'
    'NTDS'
    'RPCSs'
    'SAMSs'
    'W32Time'
)

$input = Get-ADDomainController -Filter * | Select-Object -ExpandProperty HostName
$input | ForEach-Object {
    $Servers = ($_ -split '\.')[0]
    $Servers | ForEach-Object `
    {
        $Server = $_
Get-Service -ServiceName $ServiceToCheck -ComputerName $Server)
                    {
                        $services | Select-Object -ExpandProperty ServicesDependedOn | Select-Object StartType, Status, Name, DisplayName, Machinename, @{ N = 'Service Dependency'; E = { (Get-Service -Name $_.ServicesDependedOn -ComputerName $Server | ForEach-Object { "$($_.Name): $($_.Status)" }) -join '; ' } }                  
} | Out-GridView
The Calculated Property:
@{ N = 'Service Dependency'; E = { (Get-Service -Name $_.ServicesDependedOn -ComputerName $Server | ForEach-Object { "$($_.Name): $($_.Status)" }) -join '; ' } }
Also not showing at all (blank) instead of service1: running; serviceN:stopped...

Thank you in advance.
I am also interested in solving the problem. Thank you for your inquiry.

jvierra
Posts: 14691
Joined: Tue May 22, 2007 9:57 am
Answers: 7
Has voted: 2 times
Been upvoted: 5 times

Re: Get-Service from Remote server returns wrong service list ?

Post by jvierra »

WHat is the problem you are trying to solve? You asked how to get a list of services.

Locked