# Enumerate Windows services info from remote computers

**URL:** <https://forums.powershell.org/t/enumerate-windows-services-info-from-remote-computers/7293>\
**Category:** PowerShell Help\
**Created:** [September 30, 2016, 5:42pm UTC](https://forums.powershell.org/t/enumerate-windows-services-info-from-remote-computers/7293 "2016-09-30T17:42:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rocky-cabral1](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rocky-cabral1/32/543_2.png) [@rocky-cabral1](https://forums.powershell.org/u/rocky-cabral1)\
**Post date:** [September 30, 2016, 5:42pm UTC](https://forums.powershell.org/t/enumerate-windows-services-info-from-remote-computers/7293/1 "2016-09-30T17:42:03Z")

</div>

Trying to expand a WMI query to give me table of service info for all Windows boxes from a text file.

Original script:  
$Box = read-host “Enter computer name”  
gwmi -class win32\_service -ComputerName $Box | where {$_.State -eq “Running” -and $_.StartName -notlike “LocalSystem” -and $\_.StartName -notlike “NT Authority\*”} | ft PSComputerName,DisplayName,State,StartName -AutoSize

Script trying to get working:

$results = @()  
$boxes = gc D:\boxes.txt

Foreach ($box in $boxes){  
$1 = Get-WmiObject -class win32\_service -ComputerName $box | where {$_.State -eq “Running” -and $_.StartName -notlike “LocalSystem” -and $\_.StartName -notlike “NT Authority\*”}

$out = New-Object PSObject

```
$out | Add-Member -MemberType NoteProperty -Name ComputerName -Value $1.PSComputerName
$out | Add-Member -MemberType NoteProperty -Name DisplayName -Value $1.DisplayName
$out | Add-Member -MemberType NoteProperty -Name State -Value $1.State
$out | Add-Member -MemberType NoteProperty -Name StartName -Value $1.StartName

$results += $out  

```

}  
Write-Output $results

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [October 1, 2016, 5:33am UTC](https://forums.powershell.org/t/enumerate-windows-services-info-from-remote-computers/7293/2 "2016-10-01T05:33:21Z")

</div>

You don’t actually state what the problem is; I’m guessing it’s formatting. As you’re using Write-Output I’m also guessing you don’t actually need to create the custom object.

```
$results = @()
 $boxes = Get-Content D:\boxes.txt

Foreach ($box in $boxes){
 Get-WmiObject -class win32_service -ComputerName $box | where {$_.State -eq "Running" -and $_.StartName -notlike "LocalSystem" -and $_.StartName -notlike "NT Authority*"} | Format-Table PSComputerName,DisplayName,State,StartName -AutoSize

}
```

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [October 4, 2016, 12:41pm UTC](https://forums.powershell.org/t/enumerate-windows-services-info-from-remote-computers/7293/3 "2016-10-04T12:41:09Z")

</div>

You should move the filter from where-object to Get-WmiObject as in this example

Get-CimInstance -ClassName Win32\_Service -Filter “State = ‘Running’ And NOT StartName LIKE ‘LocalSystem’ AND NOT StartName LIKE ‘NT Authority%’” |  
select PSComputerName, DisplayName, State, StartName

Performing the filtering in the CIM/WMI cmdlet means it happens on the remote box. Using Where-Object means that it happens on the local box AFTER you’ve dragged all possible objects across the network

Also displaying State is redundant as you specifically ask for services that are RUNNING

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:40pm UTC](https://forums.powershell.org/t/enumerate-windows-services-info-from-remote-computers/7293/4 "2024-05-16T20:40:12Z")

</div>


