{"id":3015,"date":"2013-08-18T00:01:00","date_gmt":"2013-08-18T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/08\/18\/weekend-scripter-understanding-powershell-in-windows-8\/"},"modified":"2013-08-18T00:01:00","modified_gmt":"2013-08-18T00:01:00","slug":"weekend-scripter-understanding-powershell-in-windows-8","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-understanding-powershell-in-windows-8\/","title":{"rendered":"Weekend Scripter: Understanding PowerShell in Windows 8"},"content":{"rendered":"<p><strong>Summary<\/strong>: Microsoft Scripting Guy, Ed Wilson, talks about understanding Windows PowerShell&nbsp;3.0 in Windows&nbsp;8.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. It is an exciting and great day! I have been working a bit to solidify the editorial calendar for the Hey, Scripting Guy! Blog. I can say that there are some absolutely awesome posts coming up in the next couple months. I am not just saying this because I am writing them. Nope. I have a great lineup of guest writers. The upcoming stuff will simply rock!<\/p>\n<h2>Windows 8 posh stuff&hellip;<\/h2>\n<p>One of the really great things about Windows&nbsp;8 is the implementation of Windows PowerShell&nbsp;3.0. But many of the really cool commands (cmdlets or functions) are not strictly Windows PowerShell&nbsp;3.0. For example, one function I use on a regular basis when I am traveling is <strong>Get-NetAdapter<\/strong>. This command tells me if a network adapter is up. Because I toggle my wireless and my Ethernet adapter connections (on or off depending on the network), I often need to see if a particular adapter is up.<\/p>\n<p>Another function I use a lot when I am traveling is the <strong>Get-NetConnectionProfile<\/strong> function. This tells me how a particular network adapter has been identified by the operating system. I can modify the profile by using <strong>Set-NetConnectionProfile<\/strong>. I need to use this a lot when I am traveling and I want to demonstrate Windows PowerShell.<\/p>\n<p>Neither of the two previously mentioned functions are part of Windows PowerShell&nbsp;3.0, per se. They are included in modules that ship with Windows&nbsp;8. The associated modules are shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-Command Get-NetConnectionProfile, Get-NetAdapter<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">CommandType&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ModuleName<\/p>\n<p style=\"padding-left: 30px\">&#8212;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8212;&#8212;&#8212;-<\/p>\n<p style=\"padding-left: 30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-NetConnectionProfile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;NetConnection<\/p>\n<p style=\"padding-left: 30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-NetAdapter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NetAdapter<\/p>\n<p>Am I being pedantic? If so, it is not my intention. It is important to know where specific functionality arises, so that when I install Windows PowerShell&nbsp;3.0 onto a computer running Windows&nbsp;7, I will know what to expect. This concept will be important when Windows&nbsp;8.1 ships with Windows PowerShell&nbsp;4.0 because Windows PowerShell&nbsp;4.0 in Windows&nbsp;8.1 will expose certain cmdlets and functions that may not be available if I install Windows PowerShell&nbsp;4.0 on a down-level system.<\/p>\n<h2>Emulating capability<\/h2>\n<p>With all the great commands in Windows&nbsp;8, it is easy to forget that the capability comes from modules that ship with the operating system, and that they are not part of Windows PowerShell&nbsp;3.0 core installation. But it is Windows PowerShell&nbsp;3.0 that makes these cool modules shine. Most of the capability comes from the CIM infrastructure that is part of the Windows Management Framework&nbsp;3.0 (where you obtain Windows PowerShell&nbsp;3.0).<\/p>\n<p>For example, the <strong>Get-NetAdapter<\/strong> function uses CIM to expose network adapter information. It is very convenient. 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\/1854.HSG-8-18-13-01.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1854.HSG-8-18-13-01.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>I can achieve the same output in Windows&nbsp;7 by using Windows PowerShell&nbsp;3.0. I use the <strong>Get-CimInstance<\/strong> cmdlet, query the Win32_NetworkAdapter WMI class, and choose the appropriate properties. The command is a bit longer than just typing <strong>Get-NetAdapter<\/strong>, but if I use it all the time, all I need to do is write my own function. Following is the command (<strong>gcim<\/strong> is the alias for <strong>Get-CimInstance<\/strong>, <strong>Select<\/strong> is the alias for <strong>Select-Object<\/strong>, and <strong>ft <\/strong>is the alias for <strong>Format-Table<\/strong>). This command is a single-line command that I broke at the pipe character for readability.<\/p>\n<p style=\"padding-left: 30px\">gcim win32_networkadapter |<\/p>\n<p style=\"padding-left: 30px\">select netconnectionid, description, interfaceindex, macaddress, speed |<\/p>\n<p style=\"padding-left: 30px\">ft * -auto<\/p>\n<p>Here is the command and the output from the command:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3173.HSG-8-18-13-02.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3173.HSG-8-18-13-02.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Join me tomorrow as I begin a series of posts called Windows PowerShell Workflow for Mere Mortals. It is a great series, and you will not want to miss it.<\/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><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about understanding Windows PowerShell&nbsp;3.0 in Windows&nbsp;8. Microsoft Scripting Guy, Ed Wilson, is here. It is an exciting and great day! I have been working a bit to solidify the editorial calendar for the Hey, Scripting Guy! Blog. I can say that there are some absolutely awesome posts coming [&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":[51,362,3,4,61,367,45],"class_list":["post-3015","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-getting-started","tag-powershell-3","tag-scripting-guy","tag-scripting-techniques","tag-weekend-scripter","tag-windows-8","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about understanding Windows PowerShell&nbsp;3.0 in Windows&nbsp;8. Microsoft Scripting Guy, Ed Wilson, is here. It is an exciting and great day! I have been working a bit to solidify the editorial calendar for the Hey, Scripting Guy! Blog. I can say that there are some absolutely awesome posts coming [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3015","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=3015"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3015\/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=3015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}