Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Collecting a list of Services

Reply
 
Old 06-27-2007   #1 (permalink)
Glenn Wilson


 
 

Collecting a list of Services


What I am trying to do is create a list of services that are set to
automatic and are stopped. I have collected several scripts to lists the
services but can not find the way to get the Startup Type and then filter it
in the script.

I have the following...
Stopped Services
get-service | where-object {$_.Status -eq "Stopped"} | sort DisplayName
Running Services
Get-Service | Where-Object {$_.Status -eq 'Running'} | sort DisplayName

So How would I list Stopped Services that are set to Automatic?

--
Glenn "Mykre" Wilson
Blog: http://www.virtualrealm.com.au/blogs/mykre

http://www.virtualrealm.com.au
XNA News and Resources from Down Under

My System SpecsSystem Spec
Old 06-27-2007   #2 (permalink)
Bart


 
 

RE: Collecting a list of Services

Hi Glen,

When you use a WMI query, the startup mode is also returned.

for example:

gwmi Win32_Service | where {$_.Startmode -eq "Manual"}

this will return all Services that are set to manuel


rgds,

Bart


"Glenn Wilson" wrote:

>
> What I am trying to do is create a list of services that are set to
> automatic and are stopped. I have collected several scripts to lists the
> services but can not find the way to get the Startup Type and then filter it
> in the script.
>
> I have the following...
> Stopped Services
> get-service | where-object {$_.Status -eq "Stopped"} | sort DisplayName
> Running Services
> Get-Service | Where-Object {$_.Status -eq 'Running'} | sort DisplayName
>
> So How would I list Stopped Services that are set to Automatic?
>
> --
> Glenn "Mykre" Wilson
> Blog: http://www.virtualrealm.com.au/blogs/mykre
>
> http://www.virtualrealm.com.au
> XNA News and Resources from Down Under

My System SpecsSystem Spec
Old 06-27-2007   #3 (permalink)
Matthias Tacke


 
 

Re: Collecting a list of Services

Bart wrote:
> "Glenn Wilson" wrote:
>> What I am trying to do is create a list of services that are set to
>> automatic and are stopped. I have collected several scripts to lists the
>> services but can not find the way to get the Startup Type and then filter it
>> in the script.
>>
>> I have the following...
>> Stopped Services
>> get-service | where-object {$_.Status -eq "Stopped"} | sort DisplayName
>> Running Services
>> Get-Service | Where-Object {$_.Status -eq 'Running'} | sort DisplayName
>>
>> So How would I list Stopped Services that are set to Automatic?
>>

> When you use a WMI query, the startup mode is also returned.
>
> for example:
>
> gwmi Win32_Service | where {$_.Startmode -eq "Manual"}
>
> this will return all Services that are set to manuel
>


Strange, the cmdlet Set-Service has a parameter

[-startupType {<Automatic> | <Manual> | <Disabled>]

which is missing in get-service (also no property)

with WMI you get inconsistently Automatic shorted to Auto:

gwmi Win32_Service | group-object StartMode
Count Name Group
----- ---- -----
10 Disabled {Alerter, ClipSrv, HidServ, Messenger...}
45 Manual {ALG, AppMgmt, aspnet_state, BITS...}
54 Auto {AntiVirScheduler, AntiVirService, ASChann....}

So for the op the proper anwer is

$a = gwmi Win32_Service
$a | where {($_.Startmode -eq "Auto") -and ($_.State -eq "Stopped")}

HTH

--
Greetings
Matthias
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Display list of log ons accounts used by windows services PowerShell
Network List Service is missing from the list of services Network & Sharing
I have no Spool Service on Services list... Vista print fax & scan
Comprehensive list of unnecessary services?? Vista installation & setup


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46