I have a script and it works by running through a list of servers and gets me serviceces that are run by domian account and whether it started ot stopped. For some reason the output just spews the service name and the account running it and whether its started or stopped. Any idea on how to tweak the script to get the actual server name on the list as well that has the services ?

$computers = get-content “C:\listofservers.txt”
Foreach ($server in $computers) {
    Get-WmiObject win32_service -ComputerName $server |
        select name, startname, startmode, state |
        where startname -like "*slt*" |
        export-csv "c:\result.csv" -NoTypeInformation -Append
}
1 Spice up

If I remember correctly, just add MachineName to your Select.

Try adding PSComputerName to your Select-Object.

Select-Object -Property Name, StartName, StartMode, State, PSComputerName

So right now i have it in a neatly formatted csv sheet neither of two above helps me. I need to have on the sheet server name, service name, accountname start mode on the csv…i only have service name, accountname start mode…

When you were testing the changes did you start with a fresh CSV file? When you use -Append to add to a CSV file it only adds fields that already exist in the file. Any additional fields are discarded.

I would use expression

$computers = get-content “C:\listofservers.txt”
Foreach ($server in $computers) {
    Get-WmiObject win32_service -ComputerName $server |
        select  @{Name = "ServerName";Expression = {$server}},name,startname, startmode, state |
        where startname -like "*slt*" |
        export-csv "c:\result.csv" -NoTypeInformation -Append
}

Loop isn’t necessary. Any reason you’re not using Get-Service?

$computers = get-content “C:\listofservers.txt”
Get-Service *slt* -ComputerName $Computers | Select MachineName,Name,ServiceName,StartType,Status | Export-Csv c:\Results.csv -NoTypeInformation

hmm get-service won’t display start-name and startname contains account with which service is running I guess he is looking for a domain account with which service is running, here looks slt is a domain name

where startname -like “slt