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?
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"
0
mjm21Author Commented:
Thanks.  I am looking to check a service on multiple servers (600+)
0
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
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

mjm21Author Commented:
Thanks a  lot!  Where  do I put the  name of the service I am trying find?
0
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"
}
0
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.
0
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
0
mjm21Author Commented:
server1
server2
server3
0
mjm21Author Commented:
single column all  the way down
0
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"
0

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.