problem listing services

test out the following code. For me, it misses out services that were installed by non system users. specifically the services im looking to list, which are those run by a service account, not a local or system account.

Param(

[string]$path = "c:\Scripts\admin-accounts.csv",

[array]$servers = @("UKSERVER","UKSERVER2")

)

 

Function Get-Accounts

{ Param ([string[]]$servers)

Foreach ($s in $servers)

{

Write-Output $s

get-wmiobject win32_service | format-table name, startname, startmode

} #end foreach $s

} #end function Get-Uptime

 

# Entry Point ***

Get-Accounts -servers $servers |format-list

so my problem is that it doesn’t list the services im actually bothered about. anyone see an issue with the code?

You’re missing -ComputerName $s in your call to Get-WmiObject. Right now all it is doing is enumerating the Win32_Service objects on your local computer, once for each of the strings in the $servers parameter.

good spot, thanks.

got it working just by adding that.

Don’t worry though, it’s an easy mistake to make. I’ve seen Don make the same mistake in one of his training videos. Also you have exposed your stea re-purposing of code because you forgot to change #end function Get-Uptime.

For best practice i believe the parameter servers should be called computername to align with other cmdlets.

haha,yeah, i am the copy and paste king.

actually i’m just converting to posh from vbs, so copying and adjusting is the norm for me right now.