Link to home
Start Free TrialLog in
Avatar of mjm21
mjm21Flag for United States of America

asked on

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

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.
Avatar of Joshua Grantom
Joshua Grantom
Flag of United States of America image

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

Avatar of mjm21

ASKER

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!
ASKER CERTIFIED SOLUTION
Avatar of Joshua Grantom
Joshua Grantom
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mjm21

ASKER

That's Perfect!!!  Thanks
Avatar of mjm21

ASKER

Thanks!
You're welcome!
Avatar of mjm21

ASKER

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.
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

Avatar of mjm21

ASKER

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
Avatar of mjm21

ASKER

oh - ok I did not see your comment.  Let me test :)
Avatar of mjm21

ASKER

Works!  Thank you Sir!
you're welcome.