We need to capture services installed on our Windows servers other than default services

Our Windows servers are provisioned with a set of default services. Application teams deploy applications on these servers. We need to capture these application services for the purpose of monitoring.

Basically, I need to use Powershell to compare the services running on our servers, compare this list with the list of our default services and output the difference in a .CSV file named after the host. For example, if the application server is named “xyz” then the output file should also be named "xyz.csv

I have not produced any code yet. I have tried but it has proven extremely difficult.

Thank you for helping out.

Kind Regards,
Victor.

Victor,

you’re not even asking any question? What help would expect?

I have tried” means you wrote code. :man_shrugging:t3:

For the vast majority of the tasks an administrator has to get done you’re not the very first one. There are very likely already code examples out there what either already fits your particular needs or can be adapted easily.

So why don’t you start searching the internet using your preferred internet search engine to find something you can start with. If you get stuck you’re welcome to come here, post your code, along with the explanation what’s not working as expected and along with the error messages you might get and we would be pleased to help you further.

BTW: Getting a list of running services from a given computer is one of the easiest tasks you can accomplish with PowerShell. Very often it is used as an example in beginner tutorials or books teaching basic PowerShell.

I know how to get services running on Windows machines using the get-service commandlet. My problem is comparing these with services running on another computer, detecting and outputting the difference.

I have searched for a solution, but what I found assumed that the number of rows (services) would be identical, only the data would be different. What I need is the opposite.

Hi Olaf,

I will keep looking… If I find something close, I’ll come back to the forum.

Kind Regards,
Victor.

And why don’t you explain that in your initial question?

In PowerShell we work with objects and their properties. Now, if you want to compare objects you can use the cmdlet

Most of us comming here not asking for help are eager to help others because it is fun for us and it is very satisfying. :wink: So we only expect a very tiny amount of effort from the questioneer to show that we won’t just be used. So just show your efforts and post the code snippets you have so far even if it’s not doing what you want yet and describe what you need. I’d bet it will not take long for someone to either point you to the right direction or even deliver what you need. :man_shrugging:t3: :man_shrugging:t3: :man_shrugging:t3:

1 Like

I don’t think you even need Compare-Object, just provide the names of your baseline list of services to the -Exclude parameter:

I have only one machine on at the moment, so this is a basic example.
You could populate $defaultServices dynamically from one of your standard servers, or from a text file.

I have used Invoke-Command as this will work with both Windows PowerShell and PowerShell Core.

# Get all services, excluding two well-known services for testing

$defaultServices = Get-Service -Exclude 'Spooler','wuauserv' | 
    Select-Object -ExpandProperty Name

# Check servers for non-default services

$serverList = 'localhost'

foreach ($Server in $ServerList) {
    Invoke-Command -ComputerName $Server { Get-Service -Exclude $Using:defaultServices } | 
        Export-Csv -Path "E:\Temp\Files\$Server.csv" -NoTypeInformation
}

Contents of CSV:

PS E:\Temp> Import-Csv E:\Temp\Files\localhost.csv | Select Name,DisplayName,Status

Name     DisplayName    Status
----     -----------    ------
Spooler  Print Spooler  Running
wuauserv Windows Update Running
1 Like

Very nice idea. :+1:t3: :love_you_gesture:t3: :star_struck:

Thank you Matt.

I had in the meantime came up with an approach after doing some web search for ideas:

On the reference server, I ran

Get-Service | export-csv -Path C:\xyz\xxx.csv

For testing, I copied xxx.csv to a target server that we need to check the difference in installed services - regardless of their status. I ran the following code on the target server:

Get-Service | export-csv -Path C:\xyz\TTT.csv
$reference = import -csv C:\xyz\xxx.csv
$Target = import -csv C:\xyz\xxx.csv
Compare-Object $reference $Target - Property Name | Where {$_.SideIndicator -eq “=>”} | Export-Csv C:\xyz\difference.csv NoTypeInformation

I recieved the output below in "difference.csv
Name SideIndicator
DHCP Server =>

The above result is correct.

We have a network share that contains the list of services installed on our servers. Each in its own .CSV file. The assistance I need now is to loop the “Compare-Object” against each of this .csv files. We have more than 2000 of them. Otherwise, I would have to do this manually.

Thank you.

I’d expect you know how to do a loop … so my question would be … what kind of assistance exactly do you need?

So you have more than 2000 servers to check or how do I understand this? How do distinguish the CSV files from each other or how to you match a CSV file with the according server?

AND PLEASE Format your code as code - DO NOT FORMAT IT AS QUOTE!

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )