Powershell script to search remote computers for certain service account

I am trying to come up with a Powershell script that will search multiple computers and list the name of the computer with what services has a specific account running that service and export to a CSV file.

Ex. ComputerName, Displayname, StartName, State
      ComputerA, BITS, UserA, running
Who is Participating?

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

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.

Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
******************* computer.txt file **************************
****************** end of computer.txt file *********************

Save the file in a text file, and save it in the same path of the script, and now the script:
$Computers = Get-content Computers.txt
$user= "UserA" # following your example.

foreach($computer in $Computers){
    $resultvariable+=Get-WmiObject win32_service -ComputerName $computer | select Name,StartMode,StartName,State |where{ $_.StartName -match "$user"} | Add-Member -MemberType noteproperty -Name "ComputerName" -value "$computer"


Open in new window

More background: https://blogs.technet.microsoft.com/heyscriptingguy/2012/02/15/the-scripting-wife-uses-powershell-to-find-service-accounts/

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
DBThomson76Author Commented:
Thank you! This can be closed.
Jose Gabriel Ortega CastroCEO Faru Bonon IT - EE Solution ExpertCommented:
Mark it as solution ( you can close it yourself) :)
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

From novice to tech pro — start learning today.