{"id":697,"date":"2014-09-12T00:01:00","date_gmt":"2014-09-12T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/09\/12\/why-are-all-these-services-starting\/"},"modified":"2014-09-12T00:01:00","modified_gmt":"2014-09-12T00:01:00","slug":"why-are-all-these-services-starting","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/why-are-all-these-services-starting\/","title":{"rendered":"Why Are All These Services Starting?"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, talks about using WMI to find out how services start.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/>&nbsp;Hey, Scripting Guy! I was looking at the processes on my workstation, and I see lots of things running. I suspect many of these are actually services. But I am wondering how I can use Windows PowerShell to find services that start automatically. For example, the great cmdlet <b>Get-Service<\/b> does not display this information. Any thoughts?<\/p>\n<p>&mdash;TL<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>&nbsp;Hello TL,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Yes, I have some thoughts. My main thought is that tomorrow begins the weekend in Charlotte, North Carolina. I am wondering, &ldquo;What I will do?&rdquo; I know I will spend some time working on my book, and maybe spend some time in the gym. I am also thinking that I also want to re-read the Dupin stories by Poe. As you may know, Poe is widely credited with writing the first detective mysteries. So it is always a great idea to go back to the beginnings&hellip;<\/p>\n<h2>WMI to the rescue<\/h2>\n<p>Speaking of going back to the beginnings&hellip;<\/p>\n<p>You are absolutely right. The <b>Get-Service<\/b> cmdlet, although easy to use and providing a great deal of information, does not display a service start mode. Here is a quick peak at that:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-12-14-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-12-14-01.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>To obtain service start mode information, we need to go old school and use the Win32_Serivce WMI class. This class has been around for a long time and it continues to work wonderfully well. It is well documented on MSDN: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa394418(v=vs.85).aspx\" target=\"_blank\">Win32_Service class<\/a>. By using the <b>Get-CimInstance<\/b> cmdlet, all I need to do is query it. Here is the command:<\/p>\n<p style=\"margin-left:30px\">Get-CimInstance Win32_Service&nbsp;<\/p>\n<p>The command and its associated output are shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-12-14-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-12-14-02.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Because the <b>Get-CimInstance<\/b> cmdlet displays the <b>StartMode<\/b> by default in the output, technically I am done with your request. However, you probably want to sort these. That is easy to do. I pipe the output to <b>Sort-Object<\/b> and specify <b>StartMode<\/b>. Here is the command:<\/p>\n<p style=\"margin-left:30px\">Get-CimInstance Win32_Service |<\/p>\n<p style=\"margin-left:30px\">Sort-Object StartMode<\/p>\n<p>The following output shows that, by default, it starts with Auto (but I could change that by specifying <b>Descending<\/b>:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-12-14-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-12-14-03.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>I may decide that I simply want numbers. I can get this type of overview by piping to <b>Group-Object<\/b>. Here is the command:<\/p>\n<p style=\"margin-left:30px\">Get-CimInstance Win32_Service |<\/p>\n<p style=\"margin-left:30px\">Sort-Object StartMode |<\/p>\n<p style=\"margin-left:30px\">Group-Object StartMode -NoElement<\/p>\n<p>The output is really nice. It is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-12-14-04.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-9-12-14-04.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>By the way&hellip;if you decide to begin monkeying around with service start modes, you have a couple of things you can do. One, you can write a script and use the <b>ChangeStartMode<\/b> method. If you do this, at least you will have documentation for what you did, and you can run another script to change things back if it doesn&rsquo;t work out. The <b>ChangeStartMode<\/b> method is also documented on MSDN: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa384896(v=vs.85).aspx\" target=\"_blank\">ChangeStartMode method of the Win32_Service class<\/a>.<\/p>\n<p>Another good thing to do is to use the <b>CheckPoint-Computer<\/b> cmdlet before you begin messing around with services. This way, if you need to restore, you can use the <b>Restore-Computer<\/b> cmdlet to fall back. If you do these things immediately before and after changes, there is a good chance that no major lasting issues will arise.<\/p>\n<p>TL, that is all there is to using WMI to find out how services start. WMI Week will continue tomorrow when I will talk about more way cool stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using WMI to find out how services start. &nbsp;Hey, Scripting Guy! I was looking at the processes on my workstation, and I see lots of things running. I suspect many of these are actually services. But I am wondering how I can use Windows PowerShell to find [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[385,31,3,4,39,45,6],"class_list":["post-697","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-cim","tag-operating-system","tag-scripting-guy","tag-scripting-techniques","tag-services","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using WMI to find out how services start. &nbsp;Hey, Scripting Guy! I was looking at the processes on my workstation, and I see lots of things running. I suspect many of these are actually services. But I am wondering how I can use Windows PowerShell to find [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/697","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=697"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/697\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}