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.
This topic is 3 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

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 */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 3 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked