Scripting Games


My Solution to Iron Scripter 2019 Preparatory Challenge 1

Anyone who has competed in the scripting games before knows that I’m always looking for a challenge when it comes to writing PowerShell code. While the scripting games haven’t been held in the last several years, they’ve somewhat been replaced by the Iron Scripter competition at the PowerShell + DevOps Global Summit and 2019 is shaping up to be no different. Think you’ve got skills? Bring them on! and Get-Involved.

The PowerShell Iron Scripter: My solution to prequel puzzle 3

I’ve been working through the Iron Scripter 2018 prequel puzzles which can be found on PowerShell.org’s website. In puzzle 3, you’re asked to create a “reusable PowerShell artifact”. To me, that almost always means a PowerShell function. One requirement is to pull information from the PowerShell.org RSS feed. Invoke-RestMethod which was introduced in PowerShell version 3.0 is the easiest way to accomplish that task. You’re also asked to display the returned information in a way that allows the user to select an item from the feed.

Announcing the Winner of the PowerShell TFM Book Contest

Two weeks ago, I started a PowerShell contest which required the participants to convert a string of text to title case. I didn’t specifically say title case but I explained that the first letter of each word should be converted to upper case and all remaining letters in each word should be converted to lower case. This was because a search on how to convert to title case with PowerShell gave away a good portion of the answer.

Windows PowerShell TFM Book Contest and Giveaway

](/images/2014/12/powershell-tfm4_cover150.jpgpowershell-tfm4_cover150)Today is the first day of Autumnalso known as fall here in North America and it’s my favorite time of the year. If nothing else, you’ve got to love the cooler weather and the changing of tree leaf colors. Last fall, a new version of the Windows PowerShell TFMbook that I co-authored along with Jason Helmickwas published and strangely enough, its design is remarkably similar to the colors that are associated with Autumn.

My Solution: August 2015 PowerShell Scripting Games Puzzle

A couple of months ago, PowerShell.org announced that the PowerShell Scripting Games had been re-imagined as a monthly puzzle. In August, the second puzzle was published. The instructions stated that a one-liner could be used if you were using a newer version of PowerShell. A public JSON endpoint can be found at https://www.telize.com/geoip and your goal is to write some PowerShell code to display output similar to the following: longitude latitude continent_code timezone --------- -------- -------------- -------- -115.

My Solution: July 2015 PowerShell Scripting Games Puzzle

Last month, PowerShell.organnounced that the PowerShell Scripting Games had been re-imagined as a monthly puzzle and the first puzzle was published. The instructions stated to use a PowerShell one-liner that produces the following output. No more than one semicolon should be used, do not use the ForEach-Object cmdlet or one of its aliases. The one-liner should be able to target more than one computer and feel free to go crazy with a really short one-liner with aliases and whatever else.

PowerShell Tip from the Head Coach of the 2014 Winter Scripting Games: Design for Performance and Efficiency!

There are several concepts that come to mind when discussing the topic of designing your PowerShell commands for performance and efficiency, but in my opinion one of the items at the top of the list is “Filtering Left” which is what I’ll be covering in this blog article. First, let’s start out by taking a look at an example of a simple one-liner command that’s poorly written from a performance and efficiency standpoint:

PowerShell Tip #3 from the Winner of the Advanced Category in the 2013 Scripting Games

In my previous blog article (PowerShell Tip #2), I left off with the subject of inline help and stated there was a better way. I’m fast-forwarding through lots of concepts and jumping right into “Advanced Functions and Scripts” with this tip because they are where you’ll find the answer to a “better way” to add inline help. The inline comments we saw in the previous tip looked like this: function Get-BiosInfo { # Attempting to retrieve the BIOS information from the local computer Get-WmiObject -Class Win32_BIOS } When looking at the syntax for this function, you can see that it has no parameters:

PowerShell Tip #2 from the Winner of the Advanced Category in the 2013 Scripting Games

Tip #2 - Comment (Document) your code! This is another one of those tips that probably isn’t very popular, but regardless of how good you are at writing PowerShell scripts and functions, they’re useless if no one else can figure out how to use them. You might be thinking that you’re the only one who uses the PowerShell code that you write, but I’m sure that you like to go on vacation just like the rest of us and none of us are going to live forever.

PowerShell Tip #1 from the Winner of the Advanced Category in the 2013 Scripting Games

In case you haven’t heard, the 2014 Winter Scripting Games are just now getting started. Regardless of your skill level with PowerShell, it couldn’t be a better time to participate since this is the first time in the history of the scripting games that you’ll be able to work as part of a team and receive proactive feedback (before your code is judged) from a team of expert coaches who use PowerShell in the real world on a daily basis.

Introducing the Coaches of the 2014 Winter Scripting Games

A few weeks ago, just before the announcement to start recruiting your team for the 2014 Winter Scripting Games, I was contacted by Don Jones and Richard Siddaway about an opportunity to become the Head Coach for the Winter Scripting Games. I was honored to have been contacted and I’m a firm believer of taking advantage of opportunities when they emerge, especially when they’re PowerShell related, so I graciously accepted.

How to Create PowerShell Script Modules and Module Manifests

My entry for the Scripting Games advanced event 4 contained four separate functions: I want to create a module that contains these functions. There are several different types of modules, but what I’ll be creating is a “Script Module”. Modules sound like something really complicated, but script modules are actually simple. Currently, I have the functions saved as a ps1 file which I dot-source to load the functions into memory, but I want to share this tool with others so it makes more sense to create a module out of it.

Using a Counter Variable in a PowerShell Workflow Foreach -Parallel Loop

As I’m sure most of my blog readers are aware, I competed in the advanced track of the Scripting Games this year and ended up doing quite well. Two first place finishes and three second places finishes with the official judges and four first place crowd score finishes. I also ended up being the overall winner of the advanced track. A few days ago someone on twitter asked me as the winner of the Scripting Games advanced track, what I would do with it?

2013 PowerShell Scripting Games Advanced Event 6 – The Grand Finale

For me, the Scripting Games have been a great learning experience this year. I’ve used many PowerShell features that I hadn’t used before such as splatting, ADSI, Workflows, and producing html webpages with PowerShell. I plan to write detailed followup blog articles on each of these topics over the next few months. Event 6 was definitely challenging since I hadn’t used workflows before but I also knew that’s what was really needed to accomplish the given task properly (In my opinion).

2013 PowerShell Scripting Games Advanced Event 4 – Auditors Love Greenbar Paper

The requirements for the 2013 Scripting Games Advanced Event 4 can be found here. For this event I created multiple functions and I’m going to quote chapter 6, section 1 of the Learn PowerShell Toolmaking in a Month of Lunches book written by Don Jones and Jeffery Hicks, published by Manning: A function should do one and only one of these things: Retrieve data from someplace Process data Output data to some place Put data into some visual format meant for human consumption

2013 PowerShell Scripting Games Advanced Event 3 – Bringing Bad Habits from the GUI to PowerShell

I’m seeing a trend with a lot of PowerShell scripters. Many of us have a GUI, non-scripting background and we moved to PowerShell because we didn’t want to be button monkeys clicking through the same options in the GUI day in and day out. I’ve always heard, if you’re going to do something more than once, do it (script it) in PowerShell. The trend I’m seeing is many are bringing their bad habit of wanting to repeat themselves over and over, day in and day out, to PowerShell.

People Who are Blogging About the 2013 Scripting Games

I’m sure that most people can easily find any of the blogs of the official judges from the 2013 Scripting Games. I recommend reading those blogs whether you’re competing in the scripting games or not since there’s a wealth of great information contained in them. The best place to find those blogs if you don’t know already is the Judges Notes section under the Scripting Games area on PowerShell.org so there’s no reason to duplicate them here.

2013 PowerShell Scripting Games Advanced Event 2 – Why NOT to use the Win32_ComputerSystem WMI Class

The majority of the entries I’ve seen for the Scripting Games event 2 are using the TotalPhysicalMemory property from the Win32_ComputerSystem WMI class to determine the total amount of physical memory in a server. The property name is “TotalPhysicalMemory” after all so that’s what it should contain, right? Not so fast, keep reading to discover why. Your manager needs an inventory of all of your company’s physical servers that are located in three different data centers which are in different parts of the country.

2013 PowerShell Scripting Games Advanced Event 2 – Attention to Detail is Everything

Here’s my approach to the 2013 PowerShell Scripting Games Advanced Event 2: When I start one of the Scripting Games events, I read and re-read the scenario because if you don’t understand the requirements, you can’t write an effect script, function, command, tool, etc. It’s not a bad idea to print out the event scenario and highlight the high-points. Here’s the scenario for Advanced Event 2 -An Inventory Intervention, I’ll place the items in bold that I would normally highlight on my printout:

Lessons Learned from the Scripting Games Advanced Event 1

This is a continuation from my previous blog titled 2013 PowerShell Scripting Games Advanced Event 1 – Parameters Don’t Always Work As Expected. This isn’t the exact script, but sections of it. You’ll notice at the bottom of the first image shown below, I retrieve the list of folder names from the files variable to keep from having to make another call to the file system. Going from one variable to another in memory is a cheap operation where as going to disk to retrieve something is more expensive from a resources standpoint.

2013 PowerShell Scripting Games Advanced Event 1 – Parameters Don’t Always Work As Expected

The scenario for this event states the following which has been paraphrased: Someone allowed log files to build up for around two years and they’re starting to causing disk space issues on the server. You need to build a tool to archive the log files because this has happened more than once. Applications write log files to a sub-folder in “C:\Application\Log”. Examples are C:\Application\Log\App1, C:\Application\Log\OtherApp, and C:\Application\Log\ThisAppAlso. The log files have random file names and a .

The Scripting Games are Coming, The Scripting Games are Coming, The Scripting Games are Coming!

This years Scripting Games are scheduled to be kicked off during the PowerShell Summit North America 2013 which begins on April 22nd. That’s about two and a half weeks away at this point. In previous years, there have been two categories and it’s my understanding that this year, there will be three categories. One for PowerShell beginners, one for advanced PowerShell scripters as in previous years, and a new category for people who aren’t actually competing in the events but want to grade or rate other peoples scripts.

Interesting How People are Claiming to Have Same Beginner 1 Solution as the Expert Solution but Still Did Not Get 5 Stars

This past weekend I posted a blog about Beginner Event #9 of the 2012 PowerShell Scripting Games and I received a comment on it from @ruddawg26. I took a look at his profile and tweets. I found a tweet that was tweeted by him Interesting how people are claiming to have same beginner 1 solution as the expert solution but still did not get 5 stars #2012SG so I decided to investigate further which is how this blog came to be.

Performance Counters – 2012 PowerShell Scripting Games Beginner Event #10

The details of the event scenario and the design points for Beginner Event #10 of the 2012 PowerShell Scripting Games can be found on the Hey, Scripting Guys! Blog. Gather all of the counter information for the processor counter set. Take three separate readings at five second intervals. This information should be appended to a single text file named servername_ProcessorCounters.txt in the Documents special folder. You’ll lose points for complexity. Use native PowerShell commands where possible.

Search Event Log – 2012 PowerShell Scripting Games Beginner Event #9

The details of the event scenario and the design points for Beginner Event #9 of the 2012 PowerShell Scripting Games can be found on the Hey, Scripting Guys! Blog. Find Veto Shutdown Events in the Application Event Log. A screenshot was provided that contains EventID 10001 and Winsrv as the source. Write a one liner to display the date of occurrence and the application name. Your command should be efficient. Complexity will cost you points.

Determine Hardware Type – 2012 PowerShell Scripting Games Beginner Event #8

The details of the event scenario and the design points for Beginner Event #8 of the 2012 PowerShell Scripting Games can be found on the Hey, Scripting Guys! Blog. Write a script to determine if a computer is a laptop or a desktop from a hardware prospective and display the output on the console. If this requires admin rights, you should detect if it is running as an admin or standard user.

Enabled Logs with Data – 2012 PowerShell Scripting Games Beginner Event #7

The details of the event scenario and the design points for Beginner Event #7 of the 2012 PowerShell Scripting Games can be found on the Hey, Scripting Guys! Blog. Display a list of enabled logs that contain data. Do not display errors. Include hidden logs. Display the complete log name and number of entries. Sort by the logs with the most entries in them. My research on this one lead me to the Use PowerShell to Query All Event Logs for Recent Events blog article on the Hey, Scripting Guy!

Working with WMI – 2012 PowerShell Scripting Games Beginner Event #6

The details of the event scenario and the design points for Beginner Event #6 of the 2012 PowerShell Scripting Games can be found on the Hey, Scripting Guys! Blog. Write a PowerShell script to determine the uptime of servers by using the WMI class WMI32_OperatingSystem. The script should display the server name, how many days, hours, and minutes the server has been up. As usual, I started out by running Get-Help Get-WMIObject to determine what the available parameters were for this cmdlet.

Finding Application Errors – 2012 PowerShell Scripting Games Beginner Event 5

The details of the event scenario and the design points for Beginner Event #5 of the 2012 PowerShell Scripting Games can be found on the Hey, Scripting Guys! Blog. Your manager has task you with producing a report of applications that are causing errors on your servers. This report should display the source and number of errors from the application log. How can I find out what PowerShell cmdlets are available to query the application event log?

Just Passing Thru – 2012 PowerShell Scripting Games Beginner Event 4

The details of the event scenario and the design points for Beginner Event #4 of the 2012 PowerShell Scripting Games can be found on the Hey, Scripting Guys! Blog. The key to this one is figuring out how to format the output as shown in the screen shot in the event scenario which is similar to the one in the image below: The PowerShell Down Under guys posted some great prep videos leading up to the beginning of the scripting games and one of them titled Scripting Games 2012 - Working with Folders gives you a head start on solving this one.

Toughest Event Yet – 2012 PowerShell Scripting Games Beginner Event #3

The details of the event scenario and the design points for Beginner Event #3 of the 2012 PowerShell Scripting Games can be found on the Hey, Scripting Guys! Blog. This was the toughest event out of the first three for me. I spent a lot of time researching how to check permissions because part of the first design point stated: “If you do not have permission off the root, create the nested folders where you have permissions”.

Get-Method | My-Madness | 2012 PowerShell Scripting Games Beginner Event #2

The details of the event scenario and the design points for Beginner Event #2 of the 2012 PowerShell Scripting Games can be found on the Hey, Scripting Guys! Blog. Listed below are my notes about the requirements and design points: Find all services that are running and can be stopped. The command must work against remote computers. Use the simplest command that will work. You do not need to write a script.

My Approach to the 2012 PowerShell Scripting Games Beginner Event #1

The details of the event scenario and the design points for Beginner Event #1 of the 2012 PowerShell Scripting Games can be found on the Hey, Scripting Guys! Blog. Listed below are my notes about the requirements and design points: Computers run Windows 7 and servers run Windows 2008 R2. They’re all in one domain. PowerShell remoting is enabled on all computers (both servers and desktops). Use PowerShell to retrieve the top ten processes based on the memory working set.

Game On! The 2012 PowerShell Scripting Games

Since this is my first year entering the PowerShell Scripting Games, I’m only submitting scripts for the beginner events but I’m also taking a look at the advanced ones to get an idea of what kind of knowledge is needed for them. It’s not too late to join in on the fun. Make sure you read the requirements of each event carefully, create your script, test it, and think about it for a while before submitting it.