Solved

Powershell / Quest script that will pull list of servers and output to csv all of the services started, stopped, automatic and manual

Posted on 2014-10-20
13
198 Views
Last Modified: 2014-10-23
Powershell / Quest script that will pull list of servers and output to csv all of the server hostname and services started, stopped, automatic and manual...etc.
0
Comment
Question by:mjm21
  • 7
  • 6
13 Comments
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40392500
Here you go, outputs a csv file for each server with all services.

$servers = GC C:\Servers.txt
foreach ($server in $servers) {
Get-Service -ComputerName $server | Select Status,Name,DisplayName | Sort-Object Status,Name,DisplayName | Export-Csv "C:\$server Services.csv" -nti
}

Open in new window

0
 

Author Comment

by:mjm21
ID: 40392546
Thanks...Need this to be on one excel spread sheet including server hostname.  So: server hostname, status, name (service) and display name.  There is a ton of servers that we need to check.   Would appreciate!
0
 
LVL 16

Accepted Solution

by:
Joshua Grantom earned 500 total points
ID: 40392561
New version

$results = @()
$servers = GC C:\Servers.txt
foreach ($server in $servers) {
$results += get-wmiobject win32_service | Select @{Name="Hostname";Expression={$server}},Name,DisplayName,@{Name="Status";Expression={$_.state}},Startmode
}
$results | Export-Csv C:\Services.csv -nti

Open in new window

0
 

Author Comment

by:mjm21
ID: 40392628
That's Perfect!!!  Thanks
0
 

Author Closing Comment

by:mjm21
ID: 40392631
Thanks!
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40392634
You're welcome!
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:mjm21
ID: 40399296
One issue!  It seems to be pulling my local services from my machine and applying to the list of servers I am trying to get that info from.
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40399303
forgot to add the -computername switch to gwmi. Here you go!

$results = @()
$servers = GC C:\Servers.txt
foreach ($server in $servers) {
$results += get-wmiobject win32_service -ComputerName $server | Select @{Name="Hostname";Expression={$server}},Name,DisplayName,@{Name="Status";Expression={$_.state}},Startmode
}
$results | Export-Csv C:\Services.csv -nti

Open in new window

0
 

Author Comment

by:mjm21
ID: 40399347
So, this first one works fine.  But creates separate spreadsheets for each server which will take too long for me to go through 700 + machine spreadsheets

$servers = GC C:\Servers.txt
foreach ($server in $servers) {
Get-Service -ComputerName $server | Select Status,Name,DisplayName | Sort-Object Status,Name,DisplayName | Export-Csv "C:\$server Services.csv" -nti

This one below takes the content of the txt file and runs.  The output is the server names etc.., but next to them is my local machine services, not the remote machine service.

$results = @()
$servers = GC C:\Servers1.txt
foreach ($server in $servers) {
$results += get-wmiobject win32_service | Select @{Name="Hostname";Expression={$server}},Name,DisplayName,@{Name="Status";Expression={$_.state}},Startmode
}
$results | Export-Csv C:\Services_result.csv -nti
0
 

Author Comment

by:mjm21
ID: 40399352
oh - ok I did not see your comment.  Let me test :)
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40399353
Lol ok
0
 

Author Comment

by:mjm21
ID: 40399413
Works!  Thank you Sir!
0
 
LVL 16

Expert Comment

by:Joshua Grantom
ID: 40399417
you're welcome.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
Resolve DNS query failed errors for Exchange
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now