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
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
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 …

749 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