{"id":167,"date":"2017-10-12T12:18:53","date_gmt":"2017-10-12T11:18:53","guid":{"rendered":"http:\/\/brgeek.com.br\/wordpress\/?p=167"},"modified":"2017-10-12T12:18:53","modified_gmt":"2017-10-12T11:18:53","slug":"powershell-ways-of-achieve-what-you-want","status":"publish","type":"post","link":"http:\/\/brgeek.com.br\/wordpress\/2017\/10\/12\/powershell-ways-of-achieve-what-you-want\/","title":{"rendered":"Powershell ways of Achieve what you want !"},"content":{"rendered":"<p>Hi Folks, have you heard that there are many ways to achieve something with PowerShell?<br \/>\nThat&#8217;s indeed true we only need to take in consideration how big is our script and how much interaction the script will do in your system because it can cause loops, resources consumption and in the end, there is a proper way to do it and you must follow that standard.<\/p>\n<p><strong>Getting properties of Windows service that is set to Automatic and it&#8217;s currently stopped <\/strong><\/p>\n<pre><code class=\"language-powershell\" data-line=\"\">\nPS C:\\Windows\\system32&gt; Get-WmiObject -class Win32_service | Where-Object -Property StartMode -EQ -Value Auto | Where-Object -Property state -EQ -Value Stopped | Format-Table\n\nExitCode Name             ProcessId StartMode State   Status\n-------- ----             --------- --------- -----   ------\n    1067 Automaton                0 Auto      Stopped OK    \n       0 gupdate                  0 Auto      Stopped OK    \n       0 MapsBroker               0 Auto      Stopped OK    \n       0 RemoteRegistry           0 Auto      Stopped OK    \n       0 sppsvc                   0 Auto      Stopped OK    \n       0 TrustedInstaller         0 Auto      Stopped OK    \n       0 WbioSrvc                 0 Auto      Stopped OK    \n       0 wuauserv                 0 Auto      Stopped OK    \n\n<\/code><\/pre>\n<pre><code class=\"language-powershell\" data-line=\"\">\nPS C:\\Windows\\system32&gt; Get-Service | Where-Object {$_.Status -eq &#039;Stopped&#039; -and $_.StartType -eq &#039;Auto&#039;}\n\nStatus   Name               DisplayName                           \n------   ----               -----------                           \nStopped  Automaton          EMC SolVe Automaton                   \nStopped  gupdate            Google Update Service (gupdate)       \nStopped  MapsBroker         Downloaded Maps Manager               \nStopped  RemoteRegistry     Remote Registry                       \nStopped  sppsvc             Software Protection                   \nStopped  TrustedInstaller   Windows Modules Installer             \nStopped  WbioSrvc           Windows Biometric Service             \nStopped  wuauserv           Windows Update                        \n<\/code><\/pre>\n<p>Do you agree both achieve the end result but which one is better?<\/p>\n<p>Here is a nice post about some best practices when scripting! Have fun <\/p>\n<p><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/05\/17\/weekend-scripter-best-practices-for-powershell-scripting-in-shared-environment\/\">Best Practices when Scripting<\/a><\/p>\n<p>Leave your comments, cheers, Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi Folks, have you heard that there are many ways to achieve something with PowerShell? That&#8217;s indeed true we only need to take in consideration how big is our script and how much interaction the script will do in your system because it can cause loops, resources consumption and in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":149,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[8,12,6,11],"class_list":["post-167","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-michael-goulart","tag-microsoft","tag-powershell","tag-script"],"jetpack_featured_media_url":"http:\/\/brgeek.com.br\/wordpress\/wp-content\/uploads\/2017\/09\/tips-tricks-hero-img.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/comments?post=167"}],"version-history":[{"count":1,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":168,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/posts\/167\/revisions\/168"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/media\/149"}],"wp:attachment":[{"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/media?parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/categories?post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/brgeek.com.br\/wordpress\/wp-json\/wp\/v2\/tags?post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}