Powershell Script to see if a certain service is installed from a list of servers and export results to .CSV file

Powershell Script to see if a certain service is installed on a list of servers and export results to .CSV file
mjm21Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kanti PrasadCommented:
Hi

Try

Get-Service | Export-Csv -path "C:\yourservicesfilename.csv"

If you need with the Status of Running etc then try the below

Get-Service | where {$_.Status -eq "Running"} | Export-Csv -path "C:\yourservicesfilename.csv"
mjm21Author Commented:
Thanks.  I am looking to check a service on multiple servers (600+)
Kanti PrasadCommented:
Hi

Try the below

Have your 600   server names in the servers.txt as "Server1","Server2","ServerN"

Save the below code as a .ps1 script --  yourscript.ps1


$servers = (Get-Content .\servers.txt)

foreach ($server in $servers){
Get-Service | Export-Csv -path "C:\yourservicesfilename.csv"
}


Run as
.\yourscript.ps1
Cloud as a Security Delivery Platform for MSSPs

Every Managed Security Service Provider (MSSP) needs a platform to deliver effective and efficient security-as-a-service to their customers. Scale, elasticity and profitability are a few of the many features that a Cloud platform offers. View our on-demand webinar to learn more!

mjm21Author Commented:
Thanks a  lot!  Where  do I put the  name of the service I am trying find?
Kanti PrasadCommented:
Hi

Sorry you can use as get-service xyz*

or just the service name

$servers = (Get-Content .\servers.txt)

foreach ($server in $servers){
Get-Service  yourservicename| Export-Csv -path "C:\yourservicesfilename.csv"
}
mjm21Author Commented:
Ok - this is what we have:

$servers = (Get-Content c:\servers.txt)
foreach ($server in $servers){
Get-Service -name bits | where {$_.Status -eq "Running"} | Export-Csv -path "C:\results.csv"
}

However, in the exported .csv it does  not list  the  server names with the service status.
Kanti PrasadCommented:
Hi

What you have in your servers.txt?

You should have something like this  "Server1","Server2","ServerN"

and save it as servers.txt
mjm21Author Commented:
server1
server2
server3
mjm21Author Commented:
single column all  the way down
Kanti PrasadCommented:
Hi

Test it with say below 3 servers. Copy the below 3 into a servers.csv file test the code then later you can use excel and copy special and transpose all your 600 servers into a single row and then append " " around them by copy & replace.

 "Server1","Server2","Server3"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.