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
202 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

806 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