<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'app:weblogs' matching tags 'Windows PowerShell' and 'Event 8'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=app:weblogs&amp;tag=Windows+PowerShell,Event+8&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'Windows PowerShell' and 'Event 8'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>Expert Commentary: 2012 Scripting Games Advanced Event 8</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/04/25/expert-commentary-2012-scripting-games-advanced-event-8.aspx</link><pubDate>Wed, 25 Apr 2012 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:16204</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Jeremy Engel, provides expert commentary for 2012 Scripting Games Advanced Event 8.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Jeremy Engel is the expert commentator for Advanced Event 8.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4382.hsg_2D00_4_2D00_25_2D00_12_2D00_adv_2D00_1.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4382.hsg_2D00_4_2D00_25_2D00_12_2D00_adv_2D00_1.jpg" alt="Image of Jeremy Engel" title="Image of Jeremy Engel" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Jeremy works in the health care industry as a lead systems engineer and architect, promoting new technologies and helping drive their acceptance and implementation. Being a fanatic of efficiency and automation, he also focuses on developing programs and scripts to ease the burden of administration for himself, his colleagues, and the community. His most notable contribution thus far is the&amp;nbsp;&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/02/14/use-the-powershell-dhcp-module-to-simplify-dhcp-management.aspx" target="_blank"&gt;&lt;b&gt;PowerShell Module for DHCP&lt;/b&gt;&lt;/a&gt;. He is currently working on releasing a multitude of other modules and scripts.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;He is a great admirer of the Windows PowerShell community and is honored to be a judge for this year&amp;rsquo;s Scripting Games. He wishes all the contestant&amp;rsquo;s happy scripting and good luck! Jeremy&amp;rsquo;s proudest contributions to this world are his three wonderful children, who together with his beautiful wife live in the bustling metropolis of Oak Ridge, North Carolina.&lt;/p&gt;
&lt;p&gt;When I was developing my script for the 2012 Scripting Games Advanced Event 8, the first question I asked myself was how best to differentiate between wired and wireless connections. I began by examining the &lt;b&gt;Win32_NetworkAdapter&lt;/b&gt; class, but I couldn&amp;rsquo;t find any reliable method therein of determining the physical media type. I thought about scanning the &lt;b&gt;NetConnectionID&lt;/b&gt; for indicators like &amp;ldquo;Wireless&amp;rdquo; or &amp;ldquo;Local Area Connection&amp;rdquo; but those were horribly imprecise, especially given the ability of users to rename them to whatever they wanted. Even without renaming the network connection on my Win8 slate, I found that the wired adapter was named &amp;ldquo;Wired Ethernet Connection&amp;rdquo; and the wireless adapter, &amp;ldquo;Wi-Fi.&amp;rdquo; As you can see, there was just no way to plan for all the possibilities. Now, as it happened, I had the beta copy of Windows PowerShell 3.0 installed on my laptop, so on a whim I typed &amp;ldquo;Get-Net&amp;rdquo; and tabbed out. To my delight a &lt;b&gt;Get-Net6to4Configuration&lt;/b&gt; cmdlet popped up, and two tabs later, I came upon &lt;b&gt;Get-NetAdapter&lt;/b&gt;!&lt;/p&gt;
&lt;p&gt;Lo and behold, there it was: the &lt;b&gt;PhysicalMediaType&lt;/b&gt; property, and it differentiated between 802.11 (wireless) and 802.3 (wired) among others. While the NetAdpater.Types.ps1 xml says that the &lt;b&gt;PhysicalMediaType&lt;/b&gt; strings will appear as &amp;ldquo;802.3&amp;rdquo; and &amp;ldquo;Native 802.11,&amp;rdquo; I decided not to use the &lt;b&gt;&amp;ndash;eq&lt;/b&gt; operator when filtering, but rather the &lt;b&gt;&amp;ndash;match&lt;/b&gt; operator, just in case additional 802.3/11 media types would be defined in the future. I also wanted to differentiate between connection state and device state. The &lt;b&gt;AdminStatus&lt;/b&gt; property worked best for the device state, with its &lt;b&gt;Up&lt;/b&gt; and &lt;b&gt;Down&lt;/b&gt; designations. And although the &lt;b&gt;Status&lt;/b&gt; property displayed aspects of the connection state, it appeared to be a viewer-friendly overall status pulling from multiple sources. That&amp;rsquo;s good for what it is, but a truer property to determine the connection state seemed to me to be &lt;b&gt;MediaConnectionState&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;Why did I care about the connection state when the event parameters didn&amp;rsquo;t call for any such analysis? When writing a script, I always try to think about who is going to use the script and what they might be expecting. Thus I wanted to show a warning message should the adapter that&amp;rsquo;s toggled into the enabled state be disconnected. That way the user can take corrective action right away, whether that be to plug-in a network cable or join a wireless network, rather than determine at some later point that they are not connected to any network.&lt;/p&gt;
&lt;p&gt;As part of the Event 8 requirements, users are to be prompted if more than one of the network adapters are enabled or disabled. I planned for that and then took it a step further and decided to give the user the ability to specify which adapter(s) they wanted to include in the toggling process. That would allow them to bypass the multiadapter prompt.&lt;/p&gt;
&lt;p&gt;Lastly, by typing &lt;b&gt;Get-Command &amp;ndash;Noun NetAdapter&lt;/b&gt; into Windows PowerShell, I found the &lt;b&gt;Disable&lt;/b&gt; and &lt;b&gt;Enable&lt;/b&gt; companion cmdlets that I would need to complete my script&amp;rsquo;s functionality.&lt;/p&gt;
&lt;p&gt;With my requirements and desired logic delineated, writing the script was pretty simple. I separated the logic for selecting the appropriate adapter and put it in its own function for two reasons: one, I wanted to be able to loop should the user provide an invalid selection; and two, I needed to use the code in four different instances and I didn&amp;rsquo;t want to have to repeat the same code over and over again. Also, I discovered that I needed to add a &lt;b&gt;Start-Sleep&lt;/b&gt; line to give the newly enabled network adapter a chance to connect.&lt;/p&gt;
&lt;p&gt;To put a pretty bow on the script, I added regions so that readers could easily understand the logical stages of the script, and then added a Help file for reference in Windows PowerShell. Here is the entire script:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;b&gt;Switch-NetworkConnection.ps1&lt;/b&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;lt;#&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; .Synopsis&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Toggles the enabled network connection between a wired and a wireless network adapter.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; .Description&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; The Switch-NetworkConnection.ps1 script toggles the enabled network connection between a wired and a wireless network adapter.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; This script can only be used on mobility platforms with PowerShell 3.0 installed and must be run as Administrator. Furthermore, only one wired and one wireless network adapter can be selected to take part in the toggling process. You can either select the desired network adapters from a dispalyed list, or specify which adapters will take part using the available parameters.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; .Parameter WiredNetworkAdapter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; This parameter specifies the wired network connection that will be used in the toggling process.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; This accepted value for this parameter is either the name of the network adapter or a NetAdapter object representing that network adapter.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; .Parameter WirelessNetworkAdapter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; This parameter specifies the wired network connection that will be used in the toggling process.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; This accepted value for this parameter is either the name of the network adapter or a NetAdapter object representing that network adapter.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; .Example&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; .\Switch-NetworkConnection.ps1&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; This example determines the wired and wireless network adapters that will be toggled. If multiple network adapters of a given type are found, the script will prompt for a choice.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; .Example&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; .\Switch-NetworkConnection.ps1 -WiredNetworkAdapter &amp;quot;Local Area Connection&amp;quot; -WirelessNetworkAdapter &amp;quot;WLAN 2&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; In this exmaple, the wired and wireless adapters were specified because multiple network adapters of each type are present and the user wanted to bypass the network adapter selection process.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; .Outputs&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Microsoft.Management.Infrastructure.CimInstance[]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; .Notes&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Name:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Switch-NetworkConnection.ps1&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Author:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Jeremy Engel&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; CreatedDate:&amp;nbsp; 03.26.2012&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; ModifiedDate: 03.29.2012&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Version:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1.0.0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#Requires -version 3.0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Param([Parameter(Mandatory=$false,Position=0)][Alias(&amp;quot;Wired&amp;quot;,&amp;quot;LAN&amp;quot;)][PSObject]$WiredNetworkAdapter,&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Parameter(Mandatory=$false,Position=1)][Alias(&amp;quot;Wireless&amp;quot;,&amp;quot;WLAN&amp;quot;)][PSObject]$WirelessNetworkAdapter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;function Get-AdapterSelection {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; Param([Parameter(Mandatory=$true)][string]$Text,&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Parameter(Mandatory=$true)][Microsoft.Management.Infrastructure.CimInstance[]]$Adapters&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; Write-Host $Text&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; for($i=0;$i-lt$Adapters.Count;$i++) { Write-Host &amp;quot;&amp;nbsp; $($i+1). $($Adapters[$i].Name)&amp;quot; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; $n = [int](Read-Host &amp;quot;Selection&amp;quot;)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; if($n -lt 1 -or $n -gt $Adapters.Count+1) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Write-Host &amp;quot;Invalid selection.&amp;quot; -ForegroundColor Red&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (Get-AdapterSelection -Type $Type -Adapters $Adapters)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; else { return $Adapters[$n-1] }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;function Main {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #region System Requirements and Runspace Validation&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; if(!(Get-WmiObject -Class Win32_Battery)) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Write-Host &amp;quot;ERROR: This script is designed for use on laptops and tablets only.&amp;quot; -ForegroundColor Red&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; if(([Security.Principal.WindowsIdentity]::GetCurrent()).Owner -ne &amp;quot;S-1-5-32-544&amp;quot;) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Write-Host &amp;quot;ERROR: This script may only be run as Administrator. Please open a PowerShell window as Administrator and try again.&amp;quot; -ForegroundColor Red&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #endregion&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #region Adapter Validation and Selection&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; $adapters = Get-NetAdapter -ErrorAction Stop&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; $wired = $adapters | Where-Object { $_.PhysicalMediaType -match &amp;quot;802.3&amp;quot; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; $wireless = $adapters | Where-Object { $_.PhysicalMediaType -match &amp;quot;802.11&amp;quot; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; if(!$adapters -or !$wireless -or !$wired) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $type = if(!$adapters){&amp;quot;any&amp;quot;}elseif(!$wireless){&amp;quot;any wireless&amp;quot;}else{&amp;quot;any wired&amp;quot;}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Write-Host &amp;quot;ERROR: You do not have $type network adapters.&amp;quot; -ForegroundColor Red&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; if($WiredNetworkAdapter) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $wired = if($WiredNetworkAdapter -is [string]) { $wired | Where-Object { $_.Name -eq $WiredNetworkAdapter } }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elseif($WiredNetworkAdapter -is [Microsoft.Management.Infrastructure.CimInstance]) { $WiredNetworkAdapter }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else { $null }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(!$wired) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Write-Host &amp;quot;ERROR: Could not locate a wired network adapter by the name of $WiredNetworkAdapter.&amp;quot; -ForegroundColor Red&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; if($WirelessNetworkAdapter) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $wireless = if($WirelessNetworkAdapter -is [string]) { $wireless | Where-Object { $_.Name -eq $WirelessNetworkAdapter } }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elseif($WirelessNetworkAdapter -is [Microsoft.Management.Infrastructure.CimInstance]) { $WirelessNetworkAdapter }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else { $null }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(!$wireless) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Write-Host &amp;quot;ERROR: Could not locate a wireless network adapter by the name of $WirelessNetworkAdapter.&amp;quot; -ForegroundColor Red&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; if($wired.Count -gt 1) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $text = &amp;quot;$($wired.Count) wired network adapters were found on your system. Please select the desired network adapter by number.&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $wired = Get-AdapterSelection -Text $text -Adapters $wired&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; if($wireless.Count -gt 1) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $text = &amp;quot;$($wireless.Count) wireless network adapters were found on your system. Please select the desired network adapter by number.&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $wireless = Get-AdapterSelection -Text $text -Adapters $wireless&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #endregion&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #region Action Determination&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; if($wired.AdminStatus -eq &amp;quot;Down&amp;quot; -and $wireless.AdminStatus -eq &amp;quot;Down&amp;quot;) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $text = &amp;quot;Both network adapters are disabled. Choose the number of the network adapter you wish to enable.&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $enableMe = Get-AdapterSelection -Text $text -Adapters $wired,$wireless&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $disableMe = $wired,$wireless | Where-Object { $_.Name -ne $enableMe.Name }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; elseif($wired.AdminStatus -eq &amp;quot;Up&amp;quot; -and $wireless.AdminStatus -eq &amp;quot;Up&amp;quot;) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $text = &amp;quot;Both network adapters are enabled. Choose the number of the network adapter you wish to disable.&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $disableMe = Get-AdapterSelection -Text $text -Adapters $wired,$wireless&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $enableMe = $wired,$wireless | Where-Object { $_.Name -ne $disableMe.Name }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; else {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $enableMe = $wired,$wireless | Where-Object { $_.AdminStatus -eq &amp;quot;Down&amp;quot; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $disableMe = $wired,$wireless | Where-Object { $_.AdminStatus -eq &amp;quot;Up&amp;quot; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #endregion&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #region Action Execution&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; $enableMe | Enable-NetAdapter -ErrorAction Stop&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; $disableMe | Disable-NetAdapter -Confirm:$false -ErrorAction Stop&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; Start-Sleep -Seconds 2 # Pause while the enabled adapter establishes a connection&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #endregion&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #region Output&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; $adapters = Get-NetAdapter&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; $check = $adapters | Where-Object { $_.Name -eq $enableMe.Name }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; if($check.MediaConnectionState -eq &amp;quot;Disconnected&amp;quot;) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Write-Host &amp;quot;WARNING: The enabled network adapter [$($check.Name)] is in a disconnected state.&amp;quot; -ForegroundColor Yellow&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; $adapters&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #endregion&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Main&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;/p&gt;
&lt;p&gt;~Jeremy&lt;/p&gt;
&lt;p&gt;2012 Scripting Games Guest Commentator Week Part 2 will continue tomorrow when we will present the scenario for Event 9.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3491849" width="1" height="1" alt="" /&gt;</description></item><item><title>Expert Commentary: 2012 Scripting Games Beginner Event 8</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/04/25/expert-commentary-2012-scripting-games-beginner-event-8.aspx</link><pubDate>Wed, 25 Apr 2012 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:16203</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft PFE, Chris Bellee, provides expert commentary for 2012 Scripting Games Beginner Event 8.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Chris Bellee is the expert commentator for Beginner Event 8.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6052.hsg_2D00_4_2D00_25_2D00_12_2D00_beg_2D00_1.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6052.hsg_2D00_4_2D00_25_2D00_12_2D00_beg_2D00_1.jpg" alt="Image of Chris Bellee" title="Image of Chris Bellee" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Chris is a premier field engineer (PFE) based in Sydney, Australia. He teaches many Windows PowerShell workshops and custom classes, as well as works on IP development that&amp;#39;s delivered worldwide to Microsoft Premier Customers. He also trains and certifies other field engineers to deliver Windows PowerShell workshops in the APAC region.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Chris is also a directory services PFE with a passion for helping customers monitor and automate their Active Directory infrastructure. He has developed many sample Windows PowerShell solutions for customers to enable them monitor and manage Active Directory.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Having previously worked as a systems engineer, Chris has extensive experience developing solutions by using a variety of languages other than Windows PowerShell, such as VBScript, Perl, JavaScript, and C# to aid his daily tasks.&lt;/p&gt;
&lt;p&gt;In beginner event 8, you are required to determine if a computer is a desktop computer or a laptop computer:&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;Event scenario&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;You are the desktop manager at a midsized enterprise company. It is inventory time, and you need to get a count of the number of laptop computers and the number of desktop computers. You decide to write a Windows PowerShell script that will count the number of desktop computers and the number of laptop computers on the network. To permit auditing, your report should include the computer name, and whether or not it is a desktop or a laptop machine.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Design points&lt;/b&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For the purposes of this scenario, your script only needs to write to the console.&lt;/li&gt;
&lt;li&gt;Your script only needs to determine laptop or desktop from a hardware perspective. You do not need to determine the version of the operating system.&lt;/li&gt;
&lt;li&gt;Your code only needs to run on a local computer.&lt;/li&gt;
&lt;li&gt;If your code requires admin rights, you should detect if the code is running as an admin or as a standard user. If your code works without requiring admin rights, you do not need to make this check.&lt;/li&gt;
&lt;li&gt;Extra points for writing a simple function that only returns a Boolean value.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;For this challenge we need to find a way to determine whether a computer is a laptop or desktop. Because the scenario states that the script should collect information from remote machines, our obvious choice to employ Windows Management Instrumentation (WMI) for the job.&lt;/p&gt;
&lt;p&gt;The first decision is which WMI class contains the data that we are interested in. In this case, there are two classes that fit the bill: Win32_ComputerSystem and Win32_SystemEnclosure. Because Windows PowerShell provides first class support for the WMI object model, it is relatively trivial to query these classes and browse the available properties by using the &lt;b&gt;Get-WMIObject&lt;/b&gt; cmdlet.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-WmiObject -Class Win32_ComputerSystem | Format-List *&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-WmiObject -Class Win32_SystemEnclosure | Format-List *&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;PCSystemType&lt;/b&gt; property in Win32_ComputerSystem contains a number that represents the form-factor of the machine. This seems to be a perfect fit until you read the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394102(v=vs.85).aspx" target="_blank"&gt;MSDN Win32_ComputerSystem class documentation&lt;/a&gt;. The &lt;b&gt;PCSystemType&lt;/b&gt; property is not available on computers running Windows XP, Windows Server 2003, Windows 2000, or Windows NT Server 4.0, so this may be less than perfect for organizations where Windows XP is still prevalent.&lt;/p&gt;
&lt;p&gt;In contrast, the &lt;b&gt;Win32_SystemEnclosure&lt;/b&gt; class is supported on down-level operating systems. Its &lt;b&gt;ChassisTypes&lt;/b&gt; property contains just the information we need. If you look at the MSDN class documentation, there are a large number of possible numeric values for this property, it also holds an array data type, so attention has to be given as to how we work with it.&lt;/p&gt;
&lt;p&gt;Now that we have the correct piece of data, we can create a function that returns a Boolean value depending on whether the target machine has a laptop or desktop form-factor. The function is named &lt;b&gt;Is-Laptop&lt;/b&gt; and it returns a Boolean value. It has a single input parameter consisting of the remote computer name to query and a single output variable called &lt;b&gt;$result&lt;/b&gt;. The output variable is set to &lt;b&gt;$false&lt;/b&gt; at the beginning of the function body.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;lt;#&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;.Synopsis&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; helper function used by Get-HardwareType&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;.EXAMPLE&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Example of how to use this cmdlet&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;function Is-Laptop {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[CmdletBinding()]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[OutputType([boolean])]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; param&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Parameter(Mandatory=$true)]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [string]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $strHostName&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $blnResult = $false&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $objWMI = Get-WmiObject -ComputerName $strHostName -Query $query -ErrorAction Stop&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch ($objWMI.ChassisTypes) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp; {$blnResult = $true} # Laptop&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10 {$blnResult = $true} # Notebook&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12 {$blnResult = $true} # Docking Station&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14 {$blnResult = $true} # Sub Notebook&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; default {}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $blnResult&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } # end function&lt;/p&gt;
&lt;p&gt;Looking at the documentation for the &lt;b&gt;Win32_SystemEnclosure&lt;/b&gt; class, you can see that there is more than one numerical value that determines if a machine is &amp;ldquo;portable.&amp;rdquo; For this reason I chose to use a switch statement to determine which of the four values that we are interested in are set. Another bonus to using a switch instead of an &amp;lsquo;if&amp;rsquo; statement is that it can automatically deal with arrays. The &lt;b&gt;ChassisTypes&lt;/b&gt; property holds an array of numbers. Although most of the time the property holds a single value, it is possible that it can hold many values. The switch statement acts like a pipeline&amp;mdash;each item in the array flows through the statement one-by-one.&lt;/p&gt;
&lt;p&gt;Although the &lt;b&gt;Is-Laptop&lt;/b&gt; function does all the work of executing the WMI query and returning a Boolean value, we define a second function that executes it. This makes the code more legible and abstracts the actual WMI query from the name resolution and error handling functionality implemented in the &lt;b&gt;Get-HardwareType&lt;/b&gt; function.&lt;/p&gt;
&lt;p&gt;Notice the process &lt;b&gt;{} &lt;/b&gt;scriptblock that contains most of the code in the &lt;b&gt;Get-HardwareType&lt;/b&gt; function. This allows the function to process machine names as pipeline input.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;quot;pc01&amp;quot;,&amp;quot;pc02&amp;quot;,&amp;quot;pc03&amp;quot; | Get-HardwareType&lt;/p&gt;
&lt;p&gt;Next, we try to resolve the short computer name to a fully qualified DNS host name by using the &lt;b&gt;GetHostByName()&lt;/b&gt; .NET static method. A new object instance is not needed to use the method. We can simply reference the type name and call the method by using the double-colon (&lt;b&gt;::&lt;/b&gt;) accessor syntax.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$objHostName = [system.net.dns]::GetHostByName($hostName)&lt;/p&gt;
&lt;p&gt;Notice that the &lt;b&gt;GetHostByName()&lt;/b&gt; method call is contained within a Try/Catch block. This will allow any name resolution failures to bypass the rest of the function, simply printing an error to the user and allowing the function to continue execution.&lt;/p&gt;
&lt;p&gt;Before executing the WMI query, we use the &lt;b&gt;Test-Connection&lt;/b&gt; cmdlet to determine whether the computer is accessible, using an ICMP (ping) packet. If this check is not performed, the WMI query will time-out when a computer is not available, slowing the script execution considerably. The &lt;b&gt;Test-Connection&lt;/b&gt; cmdlet returns a Boolean value (&lt;b&gt;$true&lt;/b&gt;) if the machine is contacted successfully, allowing us to use it directly within an &amp;lsquo;if&amp;rsquo; statement condition.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;if (Test-Connection -ComputerName $objHostName.HostName -count 1 -erroraction silentlycontinue)&lt;/p&gt;
&lt;p&gt;The final part of the function uses another Try/Catch block to enclose the call to the &lt;b&gt;Is-Laptop&lt;/b&gt; function, again allowing the script to recover from a potential terminating error.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$objResult = New-Object -TypeName psobject -Property @{&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;HostName=$objHostName.HostName;IsLaptop=(Is-Laptop -strHostName $objHostName.HostName)}&lt;/p&gt;
&lt;p&gt;The previous line creates a new Windows PowerShell object to store the name of the computer that is being tested and a Boolean value that indicates whether it is a laptop or a desktop machine. Here, we are using &lt;i&gt;&amp;ndash;Property&lt;/i&gt; to declare a hash table of name and value pairs that populate the new object&amp;rsquo;s members. The &lt;b&gt;Is-Laptop&lt;/b&gt; property stores the result of calling the &lt;b&gt;Is-Laptop&lt;/b&gt; function, which is a Boolean value.&lt;/p&gt;
&lt;p&gt;The main script execution occurs at the bottom of the script. We declare two counter variables to hold the number of desktops or laptop computers that are found.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$laptopCount = 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$desktopCount = 0&lt;/p&gt;
&lt;p&gt;To provide some input to the &lt;b&gt;Get-HardwareType&lt;/b&gt; function, we search the local Active Directory domain for the &lt;b&gt;CN&lt;/b&gt; attributes of all computer objects that don&amp;rsquo;t have the string &lt;b&gt;server&lt;/b&gt; within their &lt;b&gt;OperatingSystem&lt;/b&gt; attribute, using a &lt;b&gt;DirectorySearcher&lt;/b&gt; object. The search filter is specified by the LDAP query language that follows.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;(&amp;amp;(objectcategory=computer)(!operatingsystem=*server*))&amp;quot;)&lt;/p&gt;
&lt;p&gt;The search is executed by calling the &lt;b&gt;FindAll()&lt;/b&gt; method of the &lt;b&gt;DirectorySearcher&lt;/b&gt; object and the search results are saved in the &lt;b&gt;$arrMachine&lt;/b&gt; variable. The variable should now contain an array of short computer names that can be passed through the pipeline to the &lt;b&gt;Get-Hardware&lt;/b&gt; function. Each computer will then be connected to and evaluated, and the results will be displayed on the console.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$result = $arrMachineName | Get-HardwareType&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$result&lt;/p&gt;
&lt;p&gt;The total number of laptop and desktop form-factors can now be calculated. The &lt;b&gt;$result&lt;/b&gt; variable contains an array of &lt;b&gt;psobjects&lt;/b&gt; that are passed to a &lt;b&gt;ForEach-Object&lt;/b&gt; cmdlet that increments the &lt;b&gt;$laptopCount&lt;/b&gt; and &lt;b&gt;$desktopCount&lt;/b&gt; variables, depending on whether the current object&amp;rsquo;s &lt;b&gt;islaptop&lt;/b&gt; property is &lt;b&gt;$true&lt;/b&gt; or &lt;b&gt;$false&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;Finally, the totals can be written to the console.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;quot;Laptop Total: $laptopCount&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;quot;Desktop Total: $desktopCount&amp;quot;&lt;/p&gt;
&lt;p&gt;Following is the full script.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;lt;#&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;.Synopsis&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; helper function used by Get-HardwareType&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;.EXAMPLE&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Example of how to use this cmdlet&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;function Is-Laptop {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[CmdletBinding()]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[OutputType([boolean])]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; param&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Parameter(Mandatory=$true)]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [string]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $strHostName&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $blnResult = $false&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $objWMI = Get-WmiObject -ComputerName $strHostName -Query $query -ErrorAction Stop&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch ($objWMI.ChassisTypes) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9&amp;nbsp; {$blnResult = $true} # Laptop&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10 {$blnResult = $true} # Notebook&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12 {$blnResult = $true} # Docking Station&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14 {$blnResult = $true} # Sub Notebook&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; default {}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $blnResult&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } # end function&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;lt;#&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;.Synopsis&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; function to determine chassis type using a WMI query&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;.DESCRIPTION&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; function to determine chassis type using a WMI query&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;.EXAMPLE&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;pc01&amp;quot;,&amp;quot;pc02&amp;quot;,&amp;quot;pc03&amp;quot; | Get-HardwareType&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;function Get-HardwareType {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[CmdletBinding()]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[OutputType([psobject])]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Param&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;(&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[Parameter(Mandatory=$true,ValueFromPipeline=$true)]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$strHostName&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;process {&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; try {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $objHostName = [system.net.dns]::GetHostByName($strHostName)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $query = &amp;quot;select __SERVER,ChassisTypes from Win32_SystemEnclosure&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (Test-Connection -ComputerName $objHostName.HostName -count 1 -erroraction silentlycontinue) {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $objResult = New-Object -TypeName psobject -Property @{HostName=$objHostName.HostName;IsLaptop=(Is-Laptop -strHostName $objHostName.HostName)}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $objResult&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;Error trying to query $($objHostName.HostName)&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write-host &amp;quot;error connecting to $($objHostName.HostName)&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; write-host &amp;quot;Unable to resolve DNS address for $strHostName&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;} # end function&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;###################################################&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;# Main script execution&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;###################################################&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$laptopCount = 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$desktopCount = 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$searcher = new-object directoryservices.directorysearcher([ADSI]&amp;quot;&amp;quot;,&amp;quot;(&amp;amp;(objectcategory=computer)(!operatingsystem=*server*))&amp;quot;)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[void]$searcher.PropertiesToLoad.Add(&amp;quot;cn&amp;quot;)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$arrMachineName = $searcher.findall() | %{$_.properties.cn}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$result = $arrMachineName | Get-HardwareType&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$result&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$result | ForEach-Object {if ($_.islaptop) {$laptopCount++} else {$desktopCount++}}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;quot;Laptop Total: $laptopCount&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;quot;Desktop Total: $desktopCount&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;~Chris&lt;/p&gt;
&lt;p&gt;2012 Scripting Games Guest Commentator Week Part 2 will continue tomorrow when we will present the scenario for Event 9.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3491845" width="1" height="1" alt="" /&gt;</description></item><item><title>2012 Scripting Games Advanced Event 8: Enable Network Adapters</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/04/11/2012-scripting-games-advanced-event-8-enable-network-adapters.aspx</link><pubDate>Wed, 11 Apr 2012 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:15907</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8203.hsg_2D00_2_2D00_4_2D00_12_2D00_1.png"&gt;&lt;img title="2012 Scripting Games badge" alt="2012 Scripting Games badge" src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8203.hsg_2D00_2_2D00_4_2D00_12_2D00_1.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: In Advanced Event 8, you are required to enable and disable network adapters.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p class="TableNum-Title"&gt;&lt;strong&gt;About this event&lt;/strong&gt;&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p class="TableText"&gt;Division&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p class="TableText"&gt;Advanced&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p class="TableText"&gt;Date of Event&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p class="TableText"&gt;4/11/2012 12:01 AM&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p class="TableText"&gt;Due Date&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p class="TableText"&gt;4/18/2012 12:01 AM&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2&gt;Event scenario&lt;/h2&gt;
&lt;p&gt;You are a network consultant. As a result, you travel extensively. Your main computer is your laptop. At times, you may use a wireless network adapter to connect to wireless networks. When you are using wireless, you disable the wired network connection. And at times, you use a wired network connection&amp;mdash;when you use a wired network connection you disable the wireless network adapter. You do this to prevent bridging. Currently you use the graphical interface, and it seems to take nearly five minutes to make these changes. You would like to use Windows PowerShell to toggle your network connections. Your task in this scenario is to write a simple Windows PowerShell command to disable all enabled network connections, and enable all disabled network connections. The default output from running the script is sufficient.&lt;/p&gt;
&lt;h2&gt;Design points&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;This task requires admin rights; therefore, your script should check to ensure that it is running as an admin. If the script is not launched with proper credentials, display a message that admin rights are required.&lt;/li&gt;
&lt;li&gt;For the purposes of this scenario, you want one adapter enabled and the other disabled. If more than one adapter is enabled or disabled, you should display information about the adapters, and prompt the user for which one to enable or disable. You do not want the wired network adapter and the wireless network adapter enabled at the same time.&lt;/li&gt;
&lt;li&gt;This scenario is appropriate for a laptop, but not for a desktop computer. Therefore, your script should detect if the computer is a laptop or a desktop machine. If the computer is a desktop, the script should display a message that it only runs on laptop computers.&lt;/li&gt;
&lt;li&gt;The script should run without prompting if the default condition of one enabled network adapter and one disabled network adapter is met.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;2012 Scripting Games links&lt;/h2&gt;
&lt;p style="padding-left:30px;"&gt;&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/04/the-2012-windows-powershell-scripting-games-all-links-on-one-page.aspx" target="_blank"&gt;&lt;strong&gt;2012 Scripting Games: All Links on One Page&lt;/strong&gt;&lt;/a&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;I invite you to follow me on&amp;nbsp;&lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at&amp;nbsp;&lt;a href="mailto:scripter@microsoft.com"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the&amp;nbsp;&lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. Good luck as you compete in this year&amp;rsquo;s Scripting Games. We wish you well.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3487511" width="1" height="1" alt="" /&gt;</description></item><item><title>Expert Solution for 2011 Scripting Games Beginner Event 8: Use PowerShell to Write Disk File Information for Excel</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/04/27/expert-solution-for-2011-scripting-games-beginner-event-8-use-powershell-to-write-disk-file-information-for-excel.aspx</link><pubDate>Wed, 27 Apr 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:10138</guid><dc:creator>Anonymous</dc:creator><description>Summary : Microsoft PowerShell MVP, Doug Finke, gathers file information and writes it to a CSV file that is readable in Excel while solving 2011 Scripting Games Beginner Event 8. Microsoft Scripting Guy, Ed Wilson, here. Doug Finke is the expert commentator...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/27/expert-solution-for-2011-scripting-games-beginner-event-8-use-powershell-to-write-disk-file-information-for-excel.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3423090" width="1" height="1" alt="" /&gt;</description></item><item><title>Expert Solution for 2011 Scripting Games Advanced Event 8: Use PowerShell to Resize Images and to Remove EXIF Data</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/04/27/expert-solution-for-2011-scripting-games-advanced-event-8-use-powershell-to-resize-images-and-to-remove-exif-data.aspx</link><pubDate>Wed, 27 Apr 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:10137</guid><dc:creator>Anonymous</dc:creator><description>Summary : Microsoft PowerShell MVP, Marc van Orsouw, resizes images and removes EXIF metadata while solving 2011 Scripting Games Advanced Event 8. Microsoft Scripting Guy, Ed Wilson, here. Marc van Orsouw (MoW) is our expert commentator for Advanced Event...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/27/expert-solution-for-2011-scripting-games-advanced-event-8-use-powershell-to-resize-images-and-to-remove-exif-data.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3423128" width="1" height="1" alt="" /&gt;</description></item><item><title>The 2011 Scripting Games Advanced Event 8: Use PowerShell to Remove Metadata and Resize Images</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/04/13/the-2011-scripting-games-advanced-event-8-use-powershell-to-remove-metadata-and-resize-images.aspx</link><pubDate>Wed, 13 Apr 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:9966</guid><dc:creator>Anonymous</dc:creator><description>Summary : Advanced Event 8 in 2011 Scripting Games uses Windows PowerShell to remove metadata from image files and to resize those images. About this event Division Advanced Date of Event 4/13/2011 12:15 AM Due Date 4/20/2011 12:15 AM Event scenario You...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/13/the-2011-scripting-games-advanced-event-8-use-powershell-to-remove-metadata-and-resize-images.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3416888" width="1" height="1" alt="" /&gt;</description></item><item><title>The 2011 Scripting Games Beginner Event 8: Use PowerShell to Report Disk Space Utilization</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/04/13/the-2011-scripting-games-beginner-event-8-use-powershell-to-report-disk-space-utilization.aspx</link><pubDate>Wed, 13 Apr 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:9967</guid><dc:creator>Anonymous</dc:creator><description>Summary : Beginner Event 8 of 2011 Scripting Games uses Windows PowerShell to report disk space that is consumed by files in a folder. About this event Division Beginner Date of Event 4/13/2011 12:01 AM Due Date 4/20/2011 12:01 AM Event scenario You are...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/13/the-2011-scripting-games-beginner-event-8-use-powershell-to-report-disk-space-utilization.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3416883" width="1" height="1" alt="" /&gt;</description></item></channel></rss>