<?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 'Advanced' and 'Scripting Guy!'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=app:weblogs&amp;tag=Advanced,Scripting+Guy!&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'Advanced' and 'Scripting Guy!'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>2013 Scripting Games: Advanced Event 6</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2013/05/30/2013-scripting-games-advanced-event-6.aspx</link><pubDate>Thu, 30 May 2013 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:23823</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong style="font-size:12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size:12px;"&gt;: Scripting Games Advanced Event 6:&amp;nbsp;Dr. Scripto needs to configure virtual core servers and join them to the domain.&lt;/span&gt;&lt;span style="font-size:12px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today is the revealing of the final event for the 2013 Scripting Games. I hope you have learned tons from this year&amp;rsquo;s games and had fun too. Remember that you need to go to &lt;a href="http://www.powershell.org/" target="_blank"&gt;www.powershell.org&lt;/a&gt; to submit your event. Good luck!&lt;/p&gt;
&lt;h2&gt;The Core Configurator&lt;/h2&gt;
&lt;p&gt;Dr. Scripto has just one final challenge for you: to get out alive!&lt;/p&gt;
&lt;p&gt;No, wait&amp;hellip;that was when Bond was over for tea and crumpets last week.&lt;/p&gt;
&lt;p&gt;Ah, here we go&amp;hellip;&lt;/p&gt;
&lt;p&gt;Dr. Scripto is deploying a bunch of new virtual machines on a Server Core installation of Windows Server 2012. The virtual machines already have the operating system installed, and the local Administrator password is set to P@ssw0rd. The virtual machines are using DHCP to get an IP address. There is a DHCP server on the network named DHCP1, and it has a single DHCP scope named 10.0.0.0. The virtual machines&amp;rsquo; current computer names are not known, and they do not yet belong to the domain.&lt;/p&gt;
&lt;p&gt;You need to write a Windows PowerShell tool that accepts MAC addresses from the pipeline (as strings). Dr. Scripto has some files listing the virtual machines&amp;rsquo; MAC addresses that join the virtual machines to the domain and gives them a new computer name. Your tool needs to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Query the Server Core installation&amp;rsquo;s current dynamic IP address from the DHCP server.&lt;/li&gt;
&lt;li&gt;Join each Server Core installation to the Company.local domain. Use the domain credential Admin, with the password P@ssw0rd, to join the computer to the domain. At the same time, rename the computer. The first computer should be named SERVER1, the second SERVER2, and so forth. Allow the computer to restart.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Your tool should accept a parameter for the server base name, and that should default to SERVER. With the default, the server names will be SERVER1, SERVER2, and so on. But, if someone runs the tool and specifies FRED as the server base name, then you rename the servers to FRED1, FRED2, and so on. You can assume none of the server names exist on the network. (If they do, it&amp;rsquo;s not your fault if something breaks.)&lt;/p&gt;
&lt;p&gt;You should minimize the number of &amp;ldquo;Are you sure?&amp;rdquo; prompts that are shown while your script runs. The computers should be added to the domain&amp;rsquo;s default container for new machine objects.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s fine if you do this for one computer at a time, but when your script finishes running, all of the computers must be properly provisioned.&lt;/p&gt;
&lt;p&gt;You can safely assume that SERVER1, SERVER2, and so on do not already exist in the domain.&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;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;span style="font-size:12px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3572703" width="1" height="1" alt="" /&gt;</description></item><item><title>2013 Scripting Games: Advanced Event 5</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2013/05/23/2013-scripting-games-advanced-event-5.aspx</link><pubDate>Thu, 23 May 2013 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:23691</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;span style="font-size:12px;"&gt;&lt;strong&gt;Summary&lt;/strong&gt;: Scripting Games Advanced Event 5:&amp;nbsp;Dr. Scripto needs to create a tool to find client IP addresses from a bunch of IIS logs.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today is the release of Event 5 for the 2013 Scripting Games. Remember that they are being run and hosted at &lt;a href="http://www.powershell.org/" target="_blank"&gt;www.powershell.org&lt;/a&gt;. You will need to go to that webpage to submit your entry.&lt;/p&gt;
&lt;h2&gt;The Logfile Labyrinth&lt;/h2&gt;
&lt;p&gt;Dr. Scripto finds himself in possession of a bunch of IIS log files. (It is much like the one at &lt;a href="http://morelunches.com/files/powershell3/LogFiles.zip" target="_blank"&gt;http://morelunches.com/files/powershell3/LogFiles.zip&lt;/a&gt;, if you need one to practice with.) He&amp;rsquo;s keeping all of the log files in C:\Reporting\LogFiles, and he&amp;rsquo;s left the log files with their default file names, which he&amp;rsquo;s given a .log file name extension. All of the files are for a single website, on a single web server.&lt;/p&gt;
&lt;p&gt;He&amp;rsquo;d like you to write a tool that accepts a path, and then simply scans through each file in that path, generating a list of each unique client IP address that have been used to access the website. No IP address should appear more than once in your output, and you don&amp;rsquo;t need to sort the output in any way.&lt;/p&gt;
&lt;p&gt;Your tool should optionally accept an IP address mask, such as &amp;ldquo;192.0.1.*&amp;rdquo; and only display IP addresses that match the specified pattern. If run without a pattern, display all IP addresses.&lt;/p&gt;
&lt;p&gt;As described in &lt;a href="http://technet.microsoft.com/en-us/library/cc781851%28v=ws.10%29.aspx" target="_blank"&gt;IIS Log File Example&lt;/a&gt;, the client IP address is the first item in each log file entry. Regardless of the addresses found in the sample file, you should assume that any legal IP address may appear in the files Dr. Scripto needs to scan. Your command should scan &lt;em&gt;all&lt;/em&gt; of the files in the folder (and the folder doesn&amp;rsquo;t contain any other kind of file) and produce a single set of results. If an IP address appears in multiple log files (it&amp;rsquo;s likely that will be the case), your final output should still only list that IP address one time.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:12px;"&gt;I invite you to follow me on &lt;/span&gt;&lt;a style="font-size:12px;" href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt;&lt;span style="font-size:12px;"&gt; and &lt;/span&gt;&lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;&lt;span style="font-size:12px;"&gt;. If you have any questions, send email to me at &lt;/span&gt;&lt;a style="font-size:12px;" href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;&lt;span style="font-size:12px;"&gt;, or post your questions on the &lt;/span&gt;&lt;a style="font-size:12px;" href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;&lt;span style="font-size:12px;"&gt;. See you tomorrow. Until then, peace.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3572638" width="1" height="1" alt="" /&gt;</description></item><item><title>2013 Scripting Games: Advanced Event 4</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2013/05/16/2013-scripting-games-advanced-event-4.aspx</link><pubDate>Thu, 16 May 2013 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:23568</guid><dc:creator>Anonymous</dc:creator><description>&lt;p align="left"&gt;&lt;span style="font-size:12px;"&gt;&lt;strong&gt;Summary&lt;/strong&gt;: Scripting Games Advanced Event 4:&amp;nbsp;Dr. Scripto needs audit 20 random users from Active Directory.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Once again it is time to reveal an event for the 2013 Scripting Games that are being hosted and run by&amp;nbsp;&lt;a href="http://www.powershell.org/" target="_blank"&gt;www.powershell.org&lt;/a&gt;. Head on over to their website to submit your entry.&lt;/p&gt;
&lt;h2&gt;An Auditing Adventure&lt;/h2&gt;
&lt;p&gt;Dr. Scripto isn&amp;rsquo;t saying he dislikes auditors, but they do seem to show up at the most inconvenient times&amp;mdash;and with the oddest requests. So he&amp;rsquo;s tossing this particular auditor request over to you.&lt;/p&gt;
&lt;p&gt;This auditor would like a report that shows 20 randomly selected (well, as random as you can get) users from Active Directory. For each user, the auditor wants to see their user name, their department and title, and the last time they logged on. You also need to show the date their password was last changed, and whether the account is disabled or locked out. So that&amp;rsquo;s seven pieces of information. You&amp;rsquo;re to put that information into an HTML-based report file, and the file must show the date and time that the report was generated. Please make sure that all of the dates are normal looking, human-readable dates and times.&lt;/p&gt;
&lt;p&gt;Auditors being like they are, the &amp;ldquo;20 randomly&amp;rdquo; selected number will probably change in the future, so you&amp;rsquo;d better build this as a reusable tool. Have a parameter that specifies the number of users to pull, and default it to 20. Also parameterize the output HTML file name. Oh, but if the specified file name doesn&amp;rsquo;t end in &amp;ldquo;.html&amp;rdquo; or &amp;ldquo;.htm,&amp;rdquo; reject it. Get Windows PowerShell to do as much of that validation as possible. Dr. Scripto has to review your code, and he doesn&amp;rsquo;t want to read a lot of manual validation script.&lt;/p&gt;
&lt;p&gt;A domain admin will always run the command (on behalf of the auditor), and the resulting HTML file will be manually emailed to the requesting auditor.&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" target="_blank"&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;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&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=3569985" width="1" height="1" alt="" /&gt;</description></item><item><title>2013 Scripting Games: Advanced Event 3</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2013/05/09/2013-scripting-games-advanced-event-3.aspx</link><pubDate>Thu, 09 May 2013 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:23438</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong style="font-size:12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size:12px;"&gt;: Scripting Games Advanced Event 3:&amp;nbsp;&lt;/span&gt;&lt;span style="font-size:12px;"&gt;Dr. Scripto needs to create an HTML report for hard disk drive status.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today is the release of Event 3 for the 2013 Scripting Games. This year the Games are being administered and run by &lt;a href="http://www.powershell.org/" target="_blank"&gt;www.powershell.org&lt;/a&gt;. You need to go to their website to submit your entry.&lt;/p&gt;
&lt;h2&gt;A Disk Decision&lt;/h2&gt;
&lt;p&gt;Dr. Scripto has been fielding a lot of calls from the Help Desk lately. They&amp;rsquo;ve been asking him to look up information about the local hard drives in various servers&amp;mdash;mainly size and free space information. He doesn&amp;rsquo;t mind helping, but all the requests have been getting in the way of his naps. He&amp;rsquo;s asked you to write a tool command that can get the information for the Help Desk&amp;mdash;and he wants the output in an HTML file. The HTML file should look something like this:&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/4212.hsg_2D00_5_2D00_9_2D00_13_2D00_2.png"&gt;&lt;img style="border:0px currentColor;" title="Image of file" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4212.hsg_2D00_5_2D00_9_2D00_13_2D00_2.png" alt="Image of file" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The Doctor says that you should parameterize your command. He wants to be able to pipe one or more computer names as strings. The resulting HTML needs to go into an HTML file on disk someplace, and that file should have the computer name (for example, the computer SERVER1 should have Server1.html, SERVER2 should have Server2.html, and so on). A parameter should let him indicate the path (directory) to write the files to. Also, he wants you to pay special attention to the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The browser displays &amp;ldquo;Disk Free Space Report&amp;rdquo; in the page tab when viewing the report.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Local Fixed Disk Report&amp;rdquo; is in the Heading 2 (H2) HTML style. If you can add the computer name to that, bonus!&lt;/li&gt;
&lt;li&gt;The report ends with an HTML horizontal rule and the date and time that the report was generated.&lt;/li&gt;
&lt;li&gt;The size and free space values are shown as gigabytes (GB) and megabytes (MB) respectively, each to two decimal places.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The command you write can assume that both WMI and CIM are available on the remote computers, and that all the necessary firewall rules and authentication have already been taken care of.&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;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;span style="font-size:12px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3569725" width="1" height="1" alt="" /&gt;</description></item><item><title>2013 Scripting Games: Advanced Event 2</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2013/05/02/2013-scripting-games-advanced-event-2.aspx</link><pubDate>Thu, 02 May 2013 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:23243</guid><dc:creator>Anonymous</dc:creator><description>&lt;p align="left"&gt;&lt;strong style="font-size:12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size:12px;"&gt;: Dr. Scripto needs to create a tool to find basic information from his servers.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Welcome to Week 2 of the 2013 Scripting Games. Just in case you are not up to speed, this year The Scripting Guys are not hosting the Scripting Games. They are being hosted at&amp;nbsp;&lt;a href="http://www.powershell.org/" target="_blank"&gt;www.powershell.org&lt;/a&gt;. I am in full support of the Games, and I am posting the events here for your perusal. However, if you would like to submit an entry to the event, you must go to&amp;nbsp;&lt;a href="http://www.powershell.org/" target="_blank"&gt;www.powershell.org&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;An Inventory Intervention&lt;/h2&gt;
&lt;p&gt;Dr. Scripto finally has the budget to buy a few new virtualization host servers, but he needs to make some room in the data center to accommodate them. He thinks it makes sense to get rid of his lowest-powered old servers first&amp;hellip;but he needs to figure out which ones those are.&lt;/p&gt;
&lt;p&gt;This is just the first wave, too. There&amp;rsquo;s more budget on the horizon, so it&amp;rsquo;s possible that he&amp;rsquo;ll need to run this little report a few times. Better make a reusable tool.&lt;/p&gt;
&lt;p&gt;All of the virtualization hosts run Windows Server, but some of them don&amp;rsquo;t have Windows PowerShell installed, and they&amp;rsquo;re all running different operating system versions. The oldest operating system version is Windows 2000 Server (he knows, and he&amp;rsquo;s embarrassed, but he&amp;rsquo;s just been so darned busy). The good news is that they all belong to the same domain, and that you can rely on having a Domain Admin account to work with.&lt;/p&gt;
&lt;p&gt;The good Doctor has asked you to write a Windows PowerShell tool that can show him each server&amp;rsquo;s name, the installed version of Windows, amount of installed physical memory, and number of installed processors. For processors, he&amp;rsquo;ll be happy to get a count of cores, or sockets, or even both&amp;mdash;whatever you can reliably provide across all these versions of Windows. He has a few text files with computer names, and he&amp;rsquo;d like to pipe the computer names, as strings, to your tool, and have your tool query those computers.&lt;/p&gt;
&lt;p&gt;Oh, and in case he forgets how to use it&amp;mdash;make sure this tool of yours has a full Help display available.&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" target="_blank"&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;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3569713" width="1" height="1" alt="" /&gt;</description></item><item><title>2013 Scripting Games: Advanced Event 1</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2013/04/25/2013-scripting-games-advanced-event-1.aspx</link><pubDate>Thu, 25 Apr 2013 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:23052</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong style="font-size:12px;"&gt;Summary&lt;/strong&gt;&lt;span style="font-size:12px;"&gt;: Dr. Scripto needs to gather all log files older than 90 days and move them to an archive location.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. This is a day for the history books. Today is the first day of the 2013 Scripting Games as run by the Windows PowerShell community at &lt;a href="http://www.powershell.org/"&gt;www.powershell.org&lt;/a&gt;. Of course I am in full support mode for the Scripting Games, and I will also participate as a judge. Without further ado, here is Advanced Event 1&amp;hellip;&lt;/p&gt;
&lt;h2&gt;An Archival Atrocity&lt;/h2&gt;
&lt;p&gt;Dr. Scripto is in a tizzy! It seems that someone has allowed a series of application log files to pile up for around two years, and they&amp;rsquo;re starting to put the pinch on free disk space on a server. Your job is to help get the old files off to a new location.&lt;/p&gt;
&lt;p&gt;Actually, this happened last week, too. You might as well create a tool to do the archiving.&lt;/p&gt;
&lt;p&gt;The current set of log files are located in C:\Application\Log. There are three applications that write logs here, and each uses its own subfolder. For example, C:\Application\Log\App1, C:\Application\Log\OtherApp, and C:\Application\Log\ThisAppAlso. Within those subfolders, the filenames are random GUIDs with a .log filename extension. After they are created on disk, the files are never touched again by the applications.&lt;/p&gt;
&lt;p&gt;Remember that the Scripting Games are being hosted at &lt;a href="http://www.powershell.org/" target="_blank"&gt;www.powershell.org&lt;/a&gt;, so head on over there to submit your entry.&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;Ed Wilson, Microsoft Scripting Guy&lt;span style="font-size:12px;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3567941" width="1" height="1" alt="" /&gt;</description></item><item><title>Weekend Scripter: Lessons Learned from the 2012 Advanced Scripting Games</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/06/03/weekend-scripter-lessons-learned-from-the-2012-advanced-scripting-games.aspx</link><pubDate>Sun, 03 Jun 2012 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:16859</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: The winner of the advanced division of the 2012 Windows PowerShell Scripting Games gives tips for success.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today we have a guest blogger, Rohn Edwards, the winner of the Advanced category in the 2012 Scripting Games. Rohn and Lido Paglia, winner of the Beginner category, will be joining us in Orlando next week. As part of winning the 2012 Scripting Games, they won passes to &lt;a href="http://northamerica.msteched.com/?mtag=scriptingguys#fbid=hoxEYcqv2aL" target="_blank"&gt;Microsoft TechEd 2012&lt;/a&gt;. Today Rohn is going to talk about lessons that he learned in the 2012 Scripting Games.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Rohn Edwards has been a system administrator since 2006. He primarily works on Windows operating systems. A lot of his work involves automated operating system and software deployment via Microsoft System Center Configuration Manager. He started learning Windows PowerShell about a year ago when he realized that it can do things that are not even possible in VBScript, and he has not looked back since.&lt;/p&gt;
&lt;p&gt;Take it away, Rohn...&lt;/p&gt;
&lt;p&gt;The 2012 Scripting Games have come and gone, and I&amp;rsquo;m very happy that I participated in them this year. I am not going to even try to mention every single thing that I picked up, but I do want to talk about a few of the biggest lessons that I learned.&lt;/p&gt;
&lt;h2&gt;Participation is worth it&lt;/h2&gt;
&lt;p&gt;I think one of the biggest things I learned is that the Scripting Games are definitely worth entering, no matter your current scripting level. As this year&amp;rsquo;s games came to a close, one thing that I repeatedly found myself thinking about was how I should have participated last year. At that point, I did not know nearly as much about Windows PowerShell as I did before the games this year. I was able to talk myself into thinking that I would not do very well in the rankings, and between work and family obligations, I wouldn&amp;rsquo;t have enough time to participate anyway.&lt;/p&gt;
&lt;p&gt;After this year&amp;rsquo;s games, I now know two things about the games that I did not know last year:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The real reason for participating is to learn, and, even if you think you do not have time to participate, you should try anyway. Regardless of where you place in the final rankings, if you take the time to write and submit entries to at least some of the events, you will gain invaluable practice and experience with one of the most powerful tools the Windows operating systems have ever seen.&lt;/li&gt;
&lt;li&gt;If you truly don&amp;rsquo;t have time to submit an entry for each event, you haven&amp;rsquo;t lost out on anything because the games are free to enter.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By not participating last year, I feel like I robbed myself of an incredible learning opportunity. The ten events, along with the expert commentaries and expert judges providing feedback on your scripts, cram months&amp;rsquo; worth of scripting experience into just a few weeks&amp;rsquo; time. So, if you&amp;rsquo;re reading this and wondering if the games are worth your time, the answer is an unequivocal, &amp;ldquo;Yes&amp;rdquo;!&lt;/p&gt;
&lt;h2&gt;Comment-based Help is ridiculously simple&lt;/h2&gt;
&lt;p&gt;Before starting the games, I knew that I could define Help by adding specially formatted comments at the beginning or end of functions. I had not, however, used that feature of Windows PowerShell. Before starting the games, I read the tips that Ed and some of the guest bloggers published on the blog. I kept seeing comment-based Help mentioned, so I assumed that every one of my functions in my entries needed to have it added. I am glad that I did add Help to each of my functions because it helped me realize how incredibly simple it is to do. Everyone knows that good commenting is a must if you want to reuse any of the code that you write. Before the Games this year, I provided a block comment at the beginning of a function or script that gave a brief overview of its purpose, what it took as input, and what it gave as output. That helped when someone was reading the code, but it didn&amp;rsquo;t provide any way for a user to understand how to use it. Instead of the simple block comment, now I simply provide comment-based Help. If someone comes across the comment in the code, they can read it the same reading it by using &lt;b&gt;Get-Help&lt;/b&gt;. If not for the games, I probably would have continued to ignore the comment-based Help system for months.&lt;/p&gt;
&lt;h2&gt;Splatting&lt;/h2&gt;
&lt;p&gt;This may be one of my favorite Windows PowerShell features. A few weeks ago, I would have said that was still the newness of it affecting my judgment, but I still feel the same about it weeks after learning it and using it all the time. What is splatting? It is a way to pass parameters to another function or cmdlet by using a hash table. Here is an example of using &lt;b&gt;Get-Service&lt;/b&gt; to get the number of services with a display name that starts with &amp;ldquo;Microsoft&amp;rdquo;:&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/1614.wes_2D00_6_2D00_3_2D00_12_2D00_1.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1614.wes_2D00_6_2D00_3_2D00_12_2D00_1.jpg" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the previous example, I created a hash table called &lt;b&gt;Parameters&lt;/b&gt; with three entries: &lt;i&gt;ComputerName&lt;/i&gt;, &lt;i&gt;DisplayName&lt;/i&gt;, and &lt;i&gt;ErrorAction&lt;/i&gt;. I then &amp;ldquo;splatted&amp;rdquo; that hash table to the cmdlet and measured the number of objects returned. Next, I made the same call to &lt;b&gt;Get-Service&lt;/b&gt; without splatting. Now, why is the first call better than the second? There are several reasons, but I&amp;rsquo;ll only list a few:&lt;/p&gt;
&lt;ol start="1"&gt;
&lt;li&gt;It makes your code easier to read, especially if you are passing lots of parameters.&lt;/li&gt;
&lt;li&gt;It makes it easier to make a single call to a function or cmdlet, even when special logic is needed to avoid certain parameters being passed. For example, advanced event 2 required a function that would get service information for a specified computer or set of computers, and you had to support using alternate credentials. Because &lt;b&gt;Get-Service&lt;/b&gt; does not support alternate credentials, most entrants chose to use the WMI class Win32_Service. &lt;b&gt;Get-WMIObject&lt;/b&gt; (&lt;b&gt;gwmi&lt;/b&gt;) supports using alternate credentials, but only when you use them against a remote machine; it doesn&amp;rsquo;t support alternate credentials on the local computer.&amp;nbsp;&lt;br /&gt;With splatting, you can create a hash table that contains the alternate credentials and any other parameters you want to pass, and before calling &lt;b&gt;gwmi&lt;/b&gt;, you can check to see if you are going to run it against the local machine. If you are, you can remove the alternate credentials from the hash table. This lets you make a single call to &lt;b&gt;gwmi&lt;/b&gt; inside of your code instead of having logic that will call it with a different set of hard-coded parameters, depending on what you need to do. I did not know about splatting when I wrote the bulk of my entry for Advanced Event 2, so my method was not nearly as elegant as it could have been if I had used it.&lt;/li&gt;
&lt;li&gt;It makes creating wrapper functions very easy. That is actually how I found out about this feature. I had finished my main function for Advanced Event 2, but I wanted a wrapper function that I could create that would call my main function so that the output could be written to a file. I needed a way to forward all the parameters that were sent to my wrapper function to the underlying function that it was calling. I did not want to write code to check for each parameter and send it along if it was present. After a few minutes searching online, I came across a blog post that demonstrated splatting. If you&amp;rsquo;re wondering, all you have to do to create a wrapper function is make a function that takes the same parameters as the function that you&amp;rsquo;re wrapping, and then call it and &amp;ldquo;splat&amp;rdquo; the auto-generated &lt;b&gt;$PsBoundParameters&lt;/b&gt; hash table. If your wrapper function has parameters that the function it is wrapping does not have, all you have to do is make a copy of &lt;b&gt;$PsBoundParameters&lt;/b&gt; and remove the unneeded parameters from the hash table.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;RunSpacePools&lt;/h2&gt;
&lt;p&gt;This one blew my mind. I did not learn this myself while writing for any of the events. &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/17/expert-commentary-2012-scripting-games-advanced-event-2.aspx" target="_blank"&gt;Expert Commentary: 2012 Scripting Games Advanced Event 2&lt;/a&gt; by Boe Prox demoed this. His commentary pointed to a webcast&amp;nbsp;by Dr. Tobias Weltner, &lt;a href="http://www.idera.com/Events/RegisterWC.aspx?EventID=297" target="_blank"&gt;Speeding up Windows PowerShell: Multithreading&lt;/a&gt;. So what is it, and why do I like it so much? Multithreading within Windows PowerShell gives you the ability to, among other things, run a command locally on your machine against lots of remote machines in a fraction of the time it would take to run that same command against the machines one at a time.&lt;/p&gt;
&lt;p&gt;As long as you take thread safety into account, you should be able to use this feature to speed up any data parsing/processing that requires reading several files. &lt;b&gt;PSJobs&lt;/b&gt; can do this to some extent, but &lt;b&gt;RunSpacePools&lt;/b&gt; seem to offer more power, speed, and flexibility. The one area where I think &lt;b&gt;PSJobs &lt;/b&gt;might beat &lt;b&gt;RunSpacePools&lt;/b&gt; is simplicity. As long as you do not try to implement a limit to the number of threads you can run concurrently, it is much easier to follow what is going on when using &lt;b&gt;PSJobs&lt;/b&gt;. After checking out the examples by Dr. Tobias Weltner and Boe Prox, and understanding what is going on, I think that &lt;b&gt;RunSpacePools&lt;/b&gt; has earned a special place in my arsenal of Windows PowerShell tools.&lt;/p&gt;
&lt;p&gt;So, was participating in the 2012 Scripting Games worth it? Yes! Would I still be glad that I participated if I did not win any prizes? Absolutely! I would recommend participating in the Scripting Games to anyone, whether they are completely new or an advanced pro when it comes to Windows PowerShell. The Games provide a chance to learn and enforce invaluable new and existing Windows PowerShell knowledge. The daily prize drawings and the grand prizes are just icing on the cake!&lt;/p&gt;
&lt;p&gt;~Rohn&lt;/p&gt;
&lt;p&gt;Thanks, Rohn! 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=3501261" width="1" height="1" alt="" /&gt;</description></item><item><title>Expert Commentary: 2012 Scripting Games Advanced Event 10</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/04/27/expert-commentary-2012-scripting-games-advanced-event-10.aspx</link><pubDate>Fri, 27 Apr 2012 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:16242</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft MCC, Rich Prescott, provides expert commentary for 2012 Scripting Games Advanced Event 10.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Rich Prescott is the expert commentator for Advanced Event 10.&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/7144.hsg_2D00_4_2D00_27_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/7144.hsg_2D00_4_2D00_27_2D00_12_2D00_adv_2D00_1.jpg" alt="Photo of Rich Prescott" title="Photo of Rich Prescott" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Rich is currently working as a Windows Engineer for a market-leading global financial services firm in New York City.&amp;nbsp;He started learning Windows PowerShell in 2009 while he was working as a desktop engineer. He is an author for the Microsoft TechNet Wiki. He is also a moderator on the&amp;nbsp;&lt;a href="http://social.technet.microsoft.com/Forums/en-US/ITCG/threads" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;, and he recently received the Microsoft Community Contributor award.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Personal blog:&amp;nbsp;&lt;a href="http://blog.richprescott.com/" target="_blank"&gt;Engineering Efficiency&lt;br /&gt; &lt;/a&gt;Microsoft blog:&amp;nbsp;&lt;a href="http://blogs.technet.com/b/wikininjas/"&gt;WikiNinjas - Official Blog of TechNet Wiki&lt;br /&gt; &lt;/a&gt;Microsoft profile:&amp;nbsp;&lt;a href="http://social.technet.microsoft.com/Profile/Rich%20Prescott"&gt;Rich Prescott on TechNet&lt;br /&gt; &lt;/a&gt;Twitter:&amp;nbsp;&lt;a href="http://twitter.com/Rich_Prescott" target="_blank"&gt;@Rich_Prescott&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;&lt;b&gt;Part one: The manual way&lt;/b&gt;&lt;/h2&gt;
&lt;p&gt;Having been a server admin previously, I have dealt with misbehaving servers on multiple occasions. Typically this led to creating a data collector set in Performance Monitor, and then viewing a chart with the information or exporting the information to a BLG file for later viewing.&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/0523.hsg_2D00_4_2D00_27_2D00_12_2D00_adv_2D00_2.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/450x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0523.hsg_2D00_4_2D00_27_2D00_12_2D00_adv_2D00_2.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When we had the BLG file, it could be converted into a CSV file by using the &lt;b&gt;relog&lt;/b&gt; executable. This would create a CSV file that could satisfy three out of four of the requirements for Advanced Event 10.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Relog.exe Processor.blg &amp;ndash;f CSV &amp;ndash;o LT_processorCounters.csv&lt;/p&gt;
&lt;p&gt;But this is the 2012 Scripting Games, and what would it be without some scripting!&lt;/p&gt;
&lt;h2&gt;&lt;b&gt;Part two: The one-liner&lt;/b&gt;&lt;/h2&gt;
&lt;p&gt;After loading the Windows PowerShell console, I checked what available options there were for counters by using the following command:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-Command *counter*&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/7416.hsg_2D00_4_2D00_27_2D00_12_2D00_adv_2D00_3.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7416.hsg_2D00_4_2D00_27_2D00_12_2D00_adv_2D00_3.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After checking out the &lt;b&gt;Get-Help&lt;/b&gt; listings for the &lt;b&gt;Get-Counter&lt;/b&gt; and &lt;b&gt;Export-Counter&lt;/b&gt; cmdlets, I was able to create a simple one-liner to generate the required CSV file:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;Get-Counter -Counter (Get-Counter -ListSet Processor).Paths -MaxSamples 10 -SampleInterval 2 |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;Export-Counter -Path &amp;quot;$($Env:ComputerName)_processorCounters.csv&amp;quot; -FileFormat csv&lt;/p&gt;
&lt;p&gt;To fulfill the requirement of placing it in the &lt;i&gt;Documents&lt;/i&gt; special folder, we can use &lt;b&gt;Join-Path&lt;/b&gt; and a shortcut for the user&amp;rsquo;s documents folder.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;Get-Counter -Counter (Get-Counter -ListSet Processor).Paths -MaxSamples 10 -SampleInterval 2 |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;Export-Counter -Path (Join-Path ([environment]::getfolderpath(&amp;quot;mydocuments&amp;quot;)) &amp;quot;$($Env:ComputerName)_processorCounters.csv&amp;quot;) -FileFormat csv&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/4657.hsg_2D00_4_2D00_27_2D00_12_2D00_adv_2D00_4.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4657.hsg_2D00_4_2D00_27_2D00_12_2D00_adv_2D00_4.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now we have a mirror CSV file to what we created by using &lt;b&gt;Relog.exe&lt;/b&gt;. However, if you read the Event Scenario carefully, it states that you must capture snapshots at two-second intervals for a total of ten snapshots, and there appears to be a row missing in both of the CSV files that we generated. If we wanted to be lazy, we could simply increment the &lt;b&gt;MaxSamples&lt;/b&gt; parameter by 1, delete the first empty row in the CSV file, and call it a day. But this is the 2012 Scripting Games, and if you are going to do something, do it right!&lt;/p&gt;
&lt;h2&gt;&lt;b&gt;Part three: The advanced way&lt;/b&gt;&lt;/h2&gt;
&lt;p&gt;In my testing, I found that the &lt;b&gt;Get-Counter&lt;/b&gt; cmdlet was pulling all of the information correctly, but the &lt;b&gt;Export-Counter&lt;/b&gt; and &lt;b&gt;Relog.exe&lt;/b&gt; were not correctly outputting the data. To get around this, we can use &lt;b&gt;Get-Counter&lt;/b&gt; to pull all of the information required, parse through it ourselves, and then output to a CSV file. I created the following function, which creates an array, loops through the objects piped from &lt;b&gt;Get-Counter&lt;/b&gt;, converts them into custom &lt;b&gt;PSObjects&lt;/b&gt;, and adds them to the array.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;function Convert-RPCounter {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; Param(&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Parameter(Mandatory=$true,ValuefromPipeline=$true)]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $PerfData&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;Begin {$Results = @()}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;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; ForEach ($Sample in $PerfData){&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $obj = New-Object PSObject -Property @{TimeStamp = $Sample.TimeStamp}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ForEach($CounterSample in $Sample.CounterSamples){&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $obj | Add-Member -MemberType NoteProperty -Name $CounterSample.Path -Value $CounterSample.CookedValue&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; $Results += $obj&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;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;End {$Results}&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&gt;We then call the function as follows:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-Counter -Counter (Get-Counter -ListSet &amp;quot;Processor&amp;quot;).Paths -MaxSamples 10 -SampleInterval 2 |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;Convert-RPCounter |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;Export-Csv -Path (Join-Path ([environment]::getfolderpath(&amp;quot;mydocuments&amp;quot;)) &amp;quot;$($Env:ComputerName)_processorCounters.csv&amp;quot;) -NoTypeInformation&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/3568.hsg_2D00_4_2D00_27_2D00_12_2D00_adv_2D00_5.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3568.hsg_2D00_4_2D00_27_2D00_12_2D00_adv_2D00_5.png" alt="Image of menu" title="Image of menu" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you can see in the previous image, we now have 10 full samples at two-second intervals as required. And that&amp;rsquo;s all there is to capturing performance data with Windows PowerShell.&lt;/p&gt;
&lt;p&gt;Now starts the fun process of troubleshooting what is eating up all of my CPU&amp;hellip;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;hellip;mumbles to himself, &amp;ldquo;Where is that bothersome Script Monkey? I thought I told him to stay away from my computer!&amp;rdquo;&lt;/p&gt;
&lt;p&gt;~Rich&lt;/p&gt;
&lt;p&gt;WOW! This also concludes the 2012 Scripting Games. I want to especially thank all of &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/03/09/announcing-the-powershell-judges-for-the-2012-scripting-games.aspx" target="_blank"&gt;the judges&lt;/a&gt; and the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/04/01/2012-scripting-games-guest-commentators-announced.aspx" target="_blank"&gt;expert commentators&lt;/a&gt; for all of their hard work. I also want to thank Dia Reeves (my editor) who has done much more than basic editing these past several months leading up to the Scripting Games. I also want to extend a special thank-you to our wonderful &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/03/07/support-the-amazing-sponsors-of-the-2012-scripting-games.aspx" target="_blank"&gt;sponsors&lt;/a&gt; for all their support of this great event. I hope you had fun, and that you also found it to be a worthwhile learning endeavor.&lt;/p&gt;
&lt;p&gt;Join me tomorrow as we return to our regularly scheduled Weekend Scripter. I promise that I will not talk about the Scripting Games tomorrow&amp;mdash;well, maybe a little. By the way, if you happen to be in Virginia Beach, VA tomorrow, the Scripting Wife and I will be at the &lt;a href="http://minasiconference.wordpress.com/minasi-2012-timetable/" target="_blank"&gt;Mark Minasi Conference&lt;/a&gt; where I (along with Don Jones) will be speaking. With people like Mark Minasi and Don Jones on the agenda, how can it fail to be an exciting and fun time? Hope to see you there.&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=3493261" width="1" height="1" alt="" /&gt;</description></item><item><title>Expert Commentary: 2012 Scripting Games Advanced Event 9</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/04/26/expert-commentary-2012-scripting-games-advanced-event-9.aspx</link><pubDate>Thu, 26 Apr 2012 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:16214</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Microsoft MVP, Arnaud Petitjean, provides expert commentary for 2012 Scripting Games Advanced Event 9.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Arnaud Petitjean is the expert commentator for Advanced Event 9.&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/2063.Arnaud.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/150x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2063.Arnaud.png" alt="Photo of Arnaud Petitjean" title="Photo of Arnaud Petitjean" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Arnaud is an author, speaker, system engineer, and trainer. Arnaud is the founder of the French-speaking Windows PowerShell Community. He specializes in managing VMware (by using Windows PowerShell and PowerCLI) and in desktop virtualization.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Website:&amp;nbsp;&lt;a href="http://www.powershell-scripting.com/" target="_blank"&gt;www.PowerShell-Scripting.com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hi! This is Arnaud Petitjean from Montreal. Today we are going to learn how to deal with XML files. Like almost everything with Windows PowerShell, you will see that it is very easy and straightforward.&lt;/p&gt;
&lt;p&gt;But first, before generating any file, we need to gather the data about the computer hardware. When we deal with system information, you should immediately start thinking about Windows Management Instrumentation (WMI). Indeed, WMI is a real gold mine. With it, you can collect hardware and software information, as well as interact with a computer locally or remotely in an easy manner. The only &amp;ldquo;complicated&amp;rdquo; part of WMI is to find out where the information we need is located.&lt;/p&gt;
&lt;p&gt;You should keep in mind that for how huge WMI is, most information related to computer hardware and the operating system are located in the classes respectively named &lt;b&gt;Win32_ComputerSystem&lt;/b&gt; and &lt;b&gt;Win32_OperatingSystem&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;How do I know that? Well, it&amp;rsquo;s called &amp;ldquo;experience.&amp;rdquo; And it comes over time&amp;hellip;&lt;/p&gt;
&lt;p&gt;One of the trickiest parts of this event is, in my opinion, to get the MAC address of the primary network interface. To achieve this goal, we need to find out (one more time), where this property is located. One possibility would be to use a tool like WMI Explorer to search for the property name. We could also create our proper Windows PowerShell script based on the &lt;b&gt;Get-WmiObject&lt;/b&gt; cmdlet to look for this property. Or best of all, we could use the new cmdlet called &lt;b&gt;Get-CimClass&lt;/b&gt; in Windows PowerShell 3.0 (currently in the Beta version). This specific cmdlet has been designed to ease the WMI discoverability process.&lt;/p&gt;
&lt;p&gt;The following example shows finding the &lt;b&gt;MacAddress&lt;/b&gt; property.&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/0068.Adv1.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0068.Adv1.JPG" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The latest solution is the fastest and the easiest. Instantaneously, we get two results, which are the class names on which the MacAddress property relies. Then we have to explore one of those to see what is inside it. I personally chose the &lt;b&gt;Win32_NetworkAdapter&lt;/b&gt; class because I already solved a similar issue, and I remembered that this class worked for me. But after investigating the other one, &lt;b&gt;Win32_NetworkAdapterConfiguration&lt;/b&gt;, I can assure you that the MacAddress is also there.&lt;/p&gt;
&lt;p&gt;After we apply a filter on the adapter type to get rid of all adapters except the Ethernet adapters, and we apply a filter based on the connection status to get only the connected adapters, we remove all the virtual ones from VMWare (if any). Then we select only the first one because we suppose this is the primary one.&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/8865.Adv2.JPG"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8865.Adv2.JPG" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;After we capture all the needed properties and place the result inside of some variables, we now have to put all the properties in common. This is when the &lt;b&gt;New-Object&lt;/b&gt; cmdlet comes into play. We now are creating a custom hash table with the property names of our choice and mapping the right properties to them. Then we pass this hash table to the &lt;b&gt;Property&lt;/b&gt; parameter and we are almost done!&lt;/p&gt;
&lt;p&gt;Regarding the &lt;b&gt;PhysicalMemory&lt;/b&gt; property, we can notice several things. The first is the use of the megabyte quantifier (&lt;b&gt;MB&lt;/b&gt;). This is basically a predefined constant that aims to ease the readability of a script. It is the same but nicer and&amp;nbsp;more understandable than writing 1024*1024. We divide by 1&amp;nbsp;MB to get the result in megabytes instead of bytes. The second thing is that we truncate the result thanks to the floor static method from the .NET &lt;b&gt;Math&lt;/b&gt; class.&lt;/p&gt;
&lt;p&gt;Then we create the file name (no difficulty here) and the path to store our XML file. Because there&amp;rsquo;s no environment variable that stores the &amp;ldquo;My documents&amp;rdquo; location, we are using the &lt;b&gt;System.Environment&lt;/b&gt; .NET class to gain access to the system special folders. For more information about all the other special folders, please read &lt;a href="http://msdn.microsoft.com/en-us/library/system.environment.specialfolder(v=vs.80).aspx" target="_blank"&gt;Environment.SpecialFolder Enumeration&lt;/a&gt; in the MSDN Library.&lt;/p&gt;
&lt;p&gt;Last but not least, we can convert our final object into an XML string only by using the &lt;b&gt;ConvertTo-XML&lt;/b&gt; cmdlet, and then redirect the result to disk.&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;Getting the five extra points&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;It can happen that on some machines, some properties are null, for example, the manufacturer&amp;rsquo;s name or the computer&amp;rsquo;s model. In that case we would like our script to handle that and provide a way to add a nice &amp;lsquo;N/A&amp;rsquo; string instead of a blank value.&lt;/p&gt;
&lt;p&gt;So, one way to get the five extra points for this event, could be to check each individual property value of our resulting object (stored in the &lt;b&gt;$result&lt;/b&gt; variable), and if we detect a null value, we replace it with the string &amp;lsquo;N/A&amp;rsquo;.&lt;/p&gt;
&lt;p&gt;To do so, a generic approach is needed instead of having a ton of &lt;i&gt;if&lt;/i&gt; instructions in our script for every property. Indeed, no matter what the number of properties the object has, accessing the raw Windows PowerShell object via the &lt;b&gt;PSObject&lt;/b&gt; property, followed by a simple loop on each of the properties will do the trick. Using this technique will ensure that we won&amp;rsquo;t miss any property.&lt;/p&gt;
&lt;p&gt;~Arnaud&lt;/p&gt;
&lt;p&gt;The 2012 Scripting Games Guest Commentator Week Part 2 will continue tomorrow when we will present the scenario for Event 10.&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=3493228" width="1" height="1" alt="" /&gt;</description></item><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></channel></rss>