{"id":3400,"date":"2013-06-15T00:01:00","date_gmt":"2013-06-15T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/06\/15\/weekend-scripter-use-powershell-to-find-auto-connect-wireless-networks\/"},"modified":"2013-06-15T00:01:00","modified_gmt":"2013-06-15T00:01:00","slug":"weekend-scripter-use-powershell-to-find-auto-connect-wireless-networks","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-use-powershell-to-find-auto-connect-wireless-networks\/","title":{"rendered":"Weekend Scripter: Use PowerShell to Find Auto-Connect Wireless Networks"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Use Windows PowerShell to identify auto-connect wireless networks in Windows 8.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. One of the cool things about traveling around is that I am constantly confronted with new challenges. Invariably these new challenges tend to cause me to use Windows PowerShell. For example, at TechEd 2013 North America in New Orleans this year, the Expo Hall where I had the Scripting Guys booth contained about 5,000 computers, and at least a hundred wireless networks that were set up by various vendors for their booths.<\/p>\n<p>This, of course, caused my laptop to do the old wireless two-step. It was bouncing from network to network to network. This was in spite of the fact that I had told it to connect to the TechEd wireless network. I started looking around and discovered that the &ldquo;Manage Wireless Networks&rdquo; feature in the Network and Sharing Center is apparently removed from Windows&nbsp;8. Here is a picture of that feature in Windows&nbsp;7.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7563.6-15-13-1.jpg\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7563.6-15-13-1.jpg\" alt=\"Image of menu\" width=\"500\" height=\"360\" \/><\/a><\/p>\n<p>Inside there, it was a simple matter of selecting the network and deleting it.<\/p>\n<h2>What is the big deal with wireless networks?<\/h2>\n<p>Wireless auto-connect is a great feature for a laptop that never leaves trusted premises. So, if my laptop only follows me to the Microsoft office and back to my house, having wireless auto-connect is great. The problem is that I travel in wider circles than that. I may, for example, spend a week in a Marriott Hotel in Seattle, and then spend a few days in a Hyatt in Atlanta, and then slide on into a Hilton in Savannah. While I am at the hotel, I generally connect to the wireless network (here is where the Windows Firewall and network connection profiles come in handy). Therefore, it is irritating to have to type in the code every day I am on the network.<\/p>\n<p>After a while, my collection of auto connect wireless networks becomes rather extensive. Even in Windows&nbsp;7, I would sometimes forget to groom my wireless connection lists. So at TechEd, there were several networks that my laptop auto connected to because they had common names like Nokia, Linksys, or&nbsp; AT&amp;T (and yes, there were also some hotel-named networks).<\/p>\n<p style=\"padding-left: 30px\"><strong>Note&nbsp;&nbsp;<\/strong>From security and performance perspectives, automatically connecting to a random wireless network is a big deal.<\/p>\n<p>Apparently, I am not the first Windows PowerShell person to write about this. In fact, Lee Holmes just wrote an excellent posting about this the other day: <a href=\"http:\/\/www.leeholmes.com\/blog\/2013\/06\/06\/removing-insecure-wireless-connections-with-powershell\/\" target=\"_blank\">Removing Insecure Wireless Connections with PowerShell<\/a>. He wrapped <strong>Netsh<\/strong> to perform the tasks. For more information about the <strong>Netsh<\/strong> commands to manage Windows&nbsp;8 network connections, see <a href=\"http:\/\/windows.microsoft.com\/en-US\/windows-8\/manage-wireless-network-profiles\" target=\"_blank\">Manage wireless network profiles<\/a>.<\/p>\n<h2>Where are the network auto-connections stored?<\/h2>\n<p>I thought the network auto-connection information might be stored in the registry, but I did not see it stored there. So I began looking around, and found them in the C:\\ProgramData\\Microsoft\\Wlansvc\\Profiles\\Interfaces folder. Under this folder is a GUID for each network interface. Now, this actually becomes pretty easy to deal with, because I can obtain a list of network interface GUIDS by using the <strong>Get-NetAdapter<\/strong> function, as shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; (Get-NetAdapter).interfaceGUID<\/p>\n<p style=\"padding-left: 30px\">{006DC9B1-2CE6-4F68-A7BC-3885ED63F457}<\/p>\n<p style=\"padding-left: 30px\">{EC0A5AB0-734E-41E0-854D-C4CF2D9D0EE2}<\/p>\n<p style=\"padding-left: 30px\">{898E0A57-CEFE-4D9B-9E3C-21FCBC3C5118}<\/p>\n<p style=\"padding-left: 30px\">{1E9737CA-C7F3-4B34-9C41-EF8DA6E78521}<\/p>\n<p style=\"padding-left: 30px\">{12AED542-E967-4AB8-BD94-763AB48195E2}<\/p>\n<p style=\"padding-left: 30px\">{6E97AF3F-1DF1-47E1-8049-C148D486FFCE}<\/p>\n<p>So, all I need to do is to figure out which GUID goes to my network adapter. I use the <strong>Get-NetAdapter<\/strong> function with no parameters, and obtain the following output:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-NetAdapter<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InterfaceDescription&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ifIndex Status<\/p>\n<p style=\"padding-left: 30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;- &#8212;&#8212;<\/p>\n<p style=\"padding-left: 30px\">Ethernet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Intel(R) 82579LM Gigabit Network Con&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 13 Up<\/p>\n<p style=\"padding-left: 30px\">vEthernet (Internal)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Hyper-V Virtual Ethernet Adapter #4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 31 Up<\/p>\n<p style=\"padding-left: 30px\">vEthernet (ExternalEne&#8230; Hyper-V Virtual Ethernet Adapter #3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 27 Up<\/p>\n<p style=\"padding-left: 30px\">vEthernet (InternalSwi&#8230; Hyper-V Virtual Ethernet Adapter #2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 23 Up<\/p>\n<p style=\"padding-left: 30px\">Wi-Fi&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Intel(R) Centrino(R) Ultimate-N 6300&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 12 Not Pre&#8230;<\/p>\n<p style=\"padding-left: 30px\">Bluetooth Network Conn&#8230; Bluetooth Device (Personal Area Netw&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 16 Not Pre&#8230;<\/p>\n<p>From here, I can see my wireless network adapter is named Wi-Fi. So, I can use this information to obtain my GUID. This is shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; (Get-NetAdapter -Name &#8216;wi-fi&#8217;).interfaceGUID<\/p>\n<p style=\"padding-left: 30px\">{12AED542-E967-4AB8-BD94-763AB48195E2}<\/p>\n<p>I will use this code to get me into the appropriate folder when I write my script. The technique is shown here:<\/p>\n<p style=\"padding-left: 30px\">$GUID = (Get-NetAdapter -Name &#8216;wi-fi&#8217;).interfaceGUID<\/p>\n<p style=\"padding-left: 30px\">$path = &#8220;C:\\ProgramData\\Microsoft\\Wlansvc\\Profiles\\Interfaces\\$guid&#8221;<\/p>\n<p>Inside the wireless network adapter folder is a collection of XML documents.<\/p>\n<p>Each XML document is a wireless connection profile configuration. Inside the document appears all the information I need to manage a connection. This is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8713.hsg-6-15-13-02.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8713.hsg-6-15-13-02.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>In this image, I marked the properties I want to collect. The script itself is rather simple. I use the <strong>Get-ChildItem<\/strong> cmdlet to walk through the wireless network connection folder, I use the <strong>Foreach-Object<\/strong> cmdlet to let me work with each individual XML file, and I use the <strong>Get-Content<\/strong> cmdlet to read the XML file. I cast the contents to an XMLDOCUMENT type by using the [XML] type accelerator. This portion of the script is presented here:<\/p>\n<p style=\"padding-left: 30px\">Get-ChildItem -Path $path -Recurse |<\/p>\n<p style=\"padding-left: 30px\">Foreach-Object {<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; [xml]$c = Get-Content -path $_.fullname<\/p>\n<p style=\"padding-left: 30px\">Next I create a new custom object that picks up the wireless connection name, connection mode, and SSID value as shown here:<\/p>\n<p style=\"padding-left: 30px\">New-Object pscustomobject -Property @{<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; &#8216;name&#8217; = $c.WLANProfile.name;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; &#8216;mode&#8217; = $c.WLANProfile.connectionMode;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; &#8216;ssid&#8217; = $c.WLANProfile.SSIDConfig.SSID.hex} }<\/p>\n<p style=\"padding-left: 30px\">Following is the complete script.<\/p>\n<p style=\"padding-left: 30px\">Get-AutomaticWirelessConnections.ps1<\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px\">$GUID = (Get-NetAdapter -Name &#8216;wi-fi&#8217;).interfaceGUID<\/p>\n<p style=\"padding-left: 30px\">$path = &#8220;C:\\ProgramData\\Microsoft\\Wlansvc\\Profiles\\Interfaces\\$guid&#8221;<\/p>\n<p style=\"padding-left: 30px\">Get-ChildItem -Path $path -Recurse |<\/p>\n<p style=\"padding-left: 30px\">Foreach-Object {<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; [xml]$c = Get-Content -path $_.fullname<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; New-Object pscustomobject -Property @{<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; &#8216;name&#8217; = $c.WLANProfile.name;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; &#8216;mode&#8217; = $c.WLANProfile.connectionMode;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; &#8216;ssid&#8217; = $c.WLANProfile.SSIDConfig.SSID.hex} }<\/p>\n<p>When I run the script, the following code appears in the output pane of my Windows PowerShell ISE.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3022.hsg-6-15-13-03.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3022.hsg-6-15-13-03.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>Join me tomorrow when I talk about removing unwanted wireless auto-connect profiles.<\/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><span style=\"font-size: 12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Use Windows PowerShell to identify auto-connect wireless networks in Windows 8. Microsoft Scripting Guy, Ed Wilson, is here. One of the cool things about traveling around is that I am constantly confronted with new challenges. Invariably these new challenges tend to cause me to use Windows PowerShell. For example, at TechEd 2013 North America [&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":[36,37,3,63,61,45],"class_list":["post-3400","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-client-side-management","tag-networking","tag-scripting-guy","tag-security","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Use Windows PowerShell to identify auto-connect wireless networks in Windows 8. Microsoft Scripting Guy, Ed Wilson, is here. One of the cool things about traveling around is that I am constantly confronted with new challenges. Invariably these new challenges tend to cause me to use Windows PowerShell. For example, at TechEd 2013 North America [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3400","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=3400"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3400\/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=3400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}