Category Archives: Scripting Games

UCS Power Scripting Contest – Unleash the Power of Cisco UCS


Cisco UCS servers (both managed by UCS Manager and standalone rackmount servers) can be managed with PowerShell scripts. Cisco is running a contest looking for the best PowerShell scripts that manage, automate, monitor, and perform tasks like inventory gathering about UCS Servers and other connected infrastucture, like hypervisors, applications, and operating systems. The Cisco UCS Power Scripting Contest is now open and will run until May 11th, 2014. A winner will be announced in the DevNET Zone at Cisco Live on May 20th at 5PM PT. Head over to the contest site for more details on how to win great prizes, our celebrity judging panel and support your fellow community members! For more information head to:

UCS Scripting: http://communities.cisco.com/ucsscripting
UCS Communities: http://communities.cisco.com/ucs
UCS Developed Integrations: http://communities.cisco.com/ucsintegrations

About UCS PowerTool

Cisco UCS PowerTool for UCS Manager is a PowerShell module that helps automate and manage configurations within UCS Manager including service profiles, policies, pools, equipment, and network and storage management. Cisco UCS PowerTool for IMC is a PowerShell module that helps automate and manage configurations within a standalone C-Series rackmount server including BIOS settings, boot order, firmware updates, and administrative settings such as LDAP, syslog, SNMP, etc. Cisco UCS PowerTool enables easy integration with existing IT management processes and tools. The PowerTool cmdlets manipulate on the Cisco UCS Manager’s Management Information Tree (MIT). These cmdlets allow you to create, modify, or delete actions on the Managed Objects (MOs) in the tree.

Julie’s Comments: The Scripting Games – Winter 2014


This post comes to us from Julie Andreacola, one of the members of team Kitton Mittons, who won The Scripting Games – Winter 2014. You’re welcome to submit your thoughts about the Games as well!

The 2014 Scripting Games are over and once again, it was a terrific experience. This was my third scripting games and I was blown away with all that I learned.

The team approach was very appealing to me as I have been the PowerShell expert at my workplace so I was hoping to find a team where someone knew more than I did as I’m only intermediate in PowerShell skills. I struggled to put a team together from our local PowerShell user group for the practice event, but it just didn’t work out due to the timing and workload of potential team members. I took to Twitter to find a team that had an open spot and found the Kitton_Mittons.

The team was just what I needed. We had no expectations to win and we acknowledged that some weeks, people would not be able to participate. All of the team, but myself was located in Northern Virginia, so we arranged for a Google Hangout each evening around 7 p.m. We also had a shared repository on GitHub. Both of these tools were new for us, but were invaluable for our team collaboration. I think we only had one night with everyone in attendance. The sessions varied from discussion of elements of the script, screen sharing (nice Google Hangout feature), and general geek conversation. Two of the team traveled to Charlotte NC to join me in PowerShell Saturday 007 where we met and gained another team member for the final few events.

The learning benefits happened immediately. The first week I learned more about parameters and using them to validate inputs. I immediately began implementing them in my scripts at work, making them more robust and easier to hand off to others as I was transitioning to a new job. A couple days later, our team made our first module. I knew it was easy, but had never done it and now my script at work had a module. One of our team members made an install script that put the files and modules in the correct places. I realized the advantage of this especially when turning scripts over to users unfamiliar with PowerShell. I was able to take the same installer script and quickly customize for use in my workplace. The following weeks included getting more experience with efficiencies of script blocks and better error checking. Although many of my evenings were being taken up with PowerShell, I found the nightly sessions invaluable as our team leader, Jason Morgan, took the time to teach and explain the more complex aspects of the scripts.

The 2014 Scripting Games exceeded my expectations and truly advanced my skills. I also have a new network of System Center IT Pros. I’m starting a new job this week and I know what I learned and gained over the last 4 weeks will help me to excel in this new position. A big thank you to my team mates, coaches, judges, and the PowerShell community. Learning can be fun!

Closing the Games


The judging is complete for the fourth and final event in the 2014 Winter Scripting Games.
This Games was something very different in that we presented 4 we complex scenarios that were designed to be as close as possible to the type of tasks you may have to perform at work. The solutions required multi-file answers – there’s no way you could solve these with a one liner!

All of the teams that submitted entries rose to meet the hardest challenge I’ve seen in a Scripting Games – and I’ve taken part of judged all but the first Games.

All entries were scored by 2 judges with the judges being rotated to ensure that all judges scored each team in at least one event.

I’d like to thank the judges for their hard work and also thank the coaching team put together by Mike Robbins – most of all I’d like to thank all of the teams that entered for taking part.

In any Games we have winners and the winning teams from these Games are:
1.Kitton Mittons with 19.375 points (8 of 8 scores received)
2.TecHaH with 18.75 points (8 of 8 scores received)
3.Schnipersons with 18.5 points (8 of 8 scores received)

Congratulations to Kitton Mittons for winning the 2014 Winter Scripting Games – if a representative from the winning team could please contact Don Jones or myself we’ll see about getting your prizes to you .

The Games are closed. .
Until the next time.

What Should The Scripting Games Look Like Next Time?


If you’ve been following along with The Scripting Games over the past couple of iterations, you know that we’ve been trying some different, new things. This Winter Games, we did a team-based series of events that threw some really complex scenarios at you. However, we know some folks would like to see the next Summer Games include a less-complex track that perhaps includes a focus on one-liners.

(Not that one-liners are an essential part of a work environment, but they’re fun and a good competitive thing – this is games, after all.)

So we’re looking for your ideas. Drop a comment, and tell us how you think the next Games should be structured.

However, before you comment, understand that judging by official, expert judges gets extremely difficult. Multiple 10 events across 250 entries and you’ve got a metric butt tonne of work for our volunteers to do. Quite frankly, it’s unlikely we’ll be able to provide a score-per-entry with that kind of volume. The folks who do judging just can’t take that much time off work. Seriously, even if a judge only had to look at an entry for 2 minutes, that can easily be more than 80 hours of work to look at every entry. It just isn’t do-able.

So, in your comment, include some thoughts on what you’d like to see for the judging/scoring side as well, keeping in mind the desire of judges to also have family lives and jobs. What’s your real goal in participating in the Games? To get community feedback (comments) on what you’ve done? We can arrange that. Is it perhaps educational to have judges pick out “noteworthy” (both good and bad) entries and comment on them, as a learning guide? Or are you solely after having a “known” expert offer commentary on your entry – which isn’t something we can guarantee if there are a large number of entries?

Help us understand what you’re in it for, and give us some ideas for creating a Summer event that’s fun, as well as educational.

Testing for the Presence of a Registry Key and Value


There are a number of different ways to test for the presence of a registry key and value in PowerShell. Here’s how I like to go about it. We’ll use an example key HKLM:\SOFTWARE\TestSoftware with a single value Version:

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

Using PowerShell Parameter Validation to Make Your Day Easier


A number of entries in the Winter Scripting Games use parameter validation, but some that I have seen may not be using it correctly or to its full potential.

Writing functions or scripts require a variety of parameters which have different requirements based on a number of items. It could require a collection, objects of a certain type or even a certain range of items that it should only accept.

The idea of parameter validation is that you can specify specific checks on a parameter that is being used on a function or script. If the value or collection that is passed to the parameter doesn’t meet the specified requirements, a terminating error is thrown and the execution of the code halts and gives you an error stating (usually readable) the reason for the halt. This is very powerful and allows you to have much tighter control over the input that is going into the function. You don’t want to have your script go crazy halfway into the code execution because the values sent to the parameter were completely off of the wall.

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

Winter Scripting Games 2014 – Clarifications on Rules and Clarifications


As a note, because we’ve had a couple of requests, there are two things to remember about The Scripting Games.

Clarifications on Event Wording

Event authors, judges, and other officials are prohibited from providing further explanations or clarifications on the event scenarios. You’ll have to go on what’s in the document. if it isn’t clear, then they probably don’t care about it in terms of judging. Try to document – in your comment-based help – what you did and why, and cross your fingers.

The reason for this is that not everyone is reading these posts or the Scripting Games forum. Therefore, any response would not be seen by all competitors and would therefore un-level the playing field.

We’re a lot more interested in seeing you code creatively, consistently, and in accordance with best practices. So don’t sweat the little details.

Rebuttal to the Judges

Judges are not going to respond to requests like, “why did you judge our entry in such-and-such a way?” Judges’ scores are final, and cannot be changed. As in all competitions, everywhere, always, judges sometimes make a mistake or two. It happens. It’s also possible that a judge didn’t like the way in which you did something, and that’s why you lost a point or something. Regardless, we’re extremely appreciative of the judges’ time, and we’re not going to ask them to get in online arguments with people.

On the other hand, you’re more than welcome to solicit peer feedback on your entry. If the world agrees that the judge done you wrong, then you’ll regain your sacred honor and feel better. Or, perhaps peer feedback will grant you some new perspective.

Scripting Games event 1 close


Event 1 is over and the judging is complete.
First off congratulations to every team that posted an entry – the events in these games are different and we’ve tried to up the challenge level to account for it being a team based.

The high scorers for event 1 are:
1.Troll Bait with 22 points
2.Kitton Mittons with 22 points
3.Aliens with 20 points
4.PhillyPosh with 20 points
5.Thanks4TheInvite with 17 points
6.TecHaH with 17 points
7.Bengals with 17 points
8.TPUG THUGS with 16 points
9.DuPSOGD2 with 16 points
10.Hogans Heroes with 16 points

Congratulations to them.
Good luck to everyone with the remaining events

Reporting On Installed Windows Programs Via The Registry


Quite a common request for working with Windows machines is to report the software installed on them. If you don’t have a centralised system for reporting on client software (many places don’t) then you may turn to some form of scripted method to obtain this information.

Most people tend to head to Add / Remove Programs when thinking about what software is installed in Windows. However, not all applications will always populate information in there, depending on how they have been installed. Additionally, to query that information you would typically query the WMI class Win32_Product, however this can lead to performance issues.

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

The Scripting Games Winter 2014 – Update on Event 1 Scores


Note that scorecards for the first event will not be accurate immediately on Sunday when judging closes; we have the scores in the database, but they’re not tagged in a way the system can find them. The bug has been fixed, but I need to go through and manually re-tag the first day’s scorecards, and it’s going to take a couple of days. This also affect the leaderboard display. I hope to have it fixed over the weekend. Thanks for your patience!

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:

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

µ

Adding and Removing Items from a PowerShell Array


Adding and removing Items from a PowerShell array is a topic which can lead to some confusion, so here are a few tips for you.

Create an array and we will note the type System.Array:

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

Testing for Admin Privileges in PowerShell


Sometimes when running a PowerShell script you may need to test at the beginning whether the process it was called from had Windows admin privileges in order to be able to achieve what it needs to do. Prior to PowerShell v4 I had used something along the lines of the following to test for this condition – not the most obvious piece of code ever to be fair:

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

Winter Scripting Games 2014 Tip #2: Use #Requires to let PowerShell do the work for you


In Version 2 of PowerShell, you had the ability to use #Requires –Version 2.0 to ensure that your scripts/functions would only run at a specified PowerShell version to prevent folks running an older version from wondering why things weren’t working that well.

In this article, I will show you a couple of new additions to the #Requires statement that will make your life easier when writing functions that require specific pre-requisites rather than coding your own methods

Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article..

How to make your submissions look good in the Scripting Games site’s File window.


In the course of participating in the practice event, and working on event 1, I’ve noticed a couple of things about the way files are displayed in the File window on the Scripting Games site:

  • The site treats all files as ASCII; when you upload a Unicode file, syntax highlighting doesn’t work and you wind up with what looks like an extra blank line between every line of the original file.
  • Transcripts taken with PowerShell’s Start-Transcript command frequently contain lone Carriage Return or Line Feed characters, whereas the Scripting Games site appears to only like the CRLF pair. For example, lines that are separated by only LF (such as those in PowerShell’s error or warning output), appear as a single line in the File window of the Games site.

I’ve written a function to clean up the encoding and content of files before uploading them to the Games site. It takes advantage of the fact that Get-Content has no problem reading files with any combination of EOL characters, and that Set-Content always injects CRLF pairs between its input strings. It also searches the file for any multi-byte Unicode characters; if none were found, it converts the file encoding to ASCII for a nicer display on the Games site.

#requires -Version 3.0

function Convert-GamesFile
{
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
        [string]
        $Path,

        [switch]
        $BackupOriginal
    )

    $contents = Get-Content -LiteralPath $Path -ErrorAction Stop

    # Check for Unicode characters

    $encoding = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::Ascii

    foreach ($line in $contents)
    {
        if ([System.Text.Encoding]::UTF8.GetByteCount($line) -ne $line.Length)
        {
            Write-Warning "File '$Path' contains multi-byte characters."
            Write-Warning "File encoding will be Unicode, though this doesn't display as well on the Scripting Games site."
            
            $encoding = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::Unicode
            break
        }
    }

    # Perform updates

    if ($BackupOriginal)
    {
        Copy-Item -LiteralPath $Path -Destination ("$Path.bak") -ErrorAction Stop
    }

    $contents | Set-Content -LiteralPath $Path -Encoding $encoding -ErrorAction Stop
}