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
206 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
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…

792 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