Articles

PowerShell articles, tutorials, and guides from community experts.

Art Beane

Judge notes for event 3

This event’s entries are impressive. Scoring appears to be higher than in the earlier events, so this one must have been easier to solve. So this time, instead of talking about good and bad scripts, I’m going to comment on some of the techniques I saw.
There was some “conversation” over whether Win32_Volume or Win32_LogicalDisk was the better approach to take. Fact is, either will return the requested data. So it really doesn’t matter which one you use. The controversy seemed to include misreading or misunderstanding the requirement of reporting on “local hard drives”, which implies that you need to use -Filter “DriveType=3” (or equivalent) with either to eliminate network or CD/DVD drives.
When passing a Path parameter into a function, it’s a good practice to include [ValidateScript ({Test-Path -PathType Container})] in the definition to avoid having a file name passed in error. Doing the existence test for the path and creating it if necessary in the Begin section of the function would save some time over the various techniques used in the Process section.
One thing to remember when using a CIMSession is to close it when you’ve finished using it. A couple other points to pay attention to include accounting for the DCOM/WSMAN options when looking at remote computers and including #requires -version 3 in scripts that might be run by other people on computers that might not have PowerShell 3 installed.
Using a REGEX to validate a string parameter, such as a computer name, isn’t a bad idea, but it’s important to understand exactly what the match string means. As an example, some of the match strings included a pattern like this: "[a-zA-Z0-9.-]". This means all lower and upper case letters, any numeric digit, any character, or a minus sign. The any character (".") defeats the whole purpose of the match. It really should have been escaped to “.” to mean a period. This error would probably never appear due to the unlikelihood of a badly formatted computer name being fed into the function.
Lastly, a caution when including an optional credentials parameter. It’s probably not a good idea to default it to an empty credential object ($Credential = [System.Management.Automation.PSCredential]::Empty). If you do a if ($Credential) {} call later in the script, it will always be $true and you may end up calling for the user to enter credentials far too many times. A better solution would be to check PSBoundParameters to see if a credential object was passed in.
Hope these ideas help. Good luck in Event 4.

Boe Prox

Scripting Games 2013: Event 3 Notes

Wow, it is hard to believe that we are now halfway through the Scripting Games! As the events have progressed, I have seen a lot of improvement with the techniques as well as seeing new techniques that continue to impress me. On the flip side, I have seen some mistakes or assumptions when coding that cause a potential 5 star script to be a 2 or 3 star script. The best part about all of this is that we are all (yes, even the judges) learning new things that can only help to improve everyone"™s scripting knowledge. Check out the rest of the article here.

Don Jones
Scripting Games

Meet the Scripting Games Judges: Bartek Bielawski

Bartosz (Bartek) Bielawski is a busy IT Administrator with an international company, PAREXEL. He loves PowerShell and automation. That love earned him the honor of Microsoft MVP. He shares his knowledge mainly on his blogs: in English (http://becomelotr.wordpress.com) and Polish (http://powershellpl.net) and through articles published in the Polish IT Professional (http://it-professional.pl) magazine. He is co-author of PowerShell Deep Dives book (http://www.manning.com/hicks/). He loves good code that takes advantage of PowerShell pipeline and advanced functions grouped in modules.

Don Jones
Scripting Games

Scripting Games Event 2 Winners

We’re pleased to announce the winners for Event 2 of The Scripting Games 2013!
Winners: You can log into The Scripting Games Web site and go to your Profile page to see your prize. You will be given a prize redemption code and either a URL where you can redeem it, or an e-mail address of the prize provider (they will need the redemption code). All prizes must be claimed by the end of July 2013. I will list winners by username; if you used your e-mail address as your username, then a portion of that will be truncated for your privacy. Anyone can log in and check their Profile page to see if they’ve won a prize.

Don Jones
PowerShell Summit

Announcing the PowerShell Summit North America 2014

The PowerShell Summit North America 2014 will be held April 28, 29, and 30 at the Meydenbauer Center on Northeast 6th Street in Bellevue, WA.
Your membership in the PowerShell Summit also makes you a yearlong member of PowerShell.org, the online hub for the PowerShell community. Membership includes a daily continental breakfast, daily hot lunch, and three tracks of expert-led lectures and discussions. 2014 tracks include:

  • INTERNALS: Inner secrets of PowerShell, suitable for developers and admins alike.
  • DEEP DIVES: Dig into technically rich topics related to the shell itself and broad administrative tasks.
  • DOMAIN SPECIFIC: Focus on managing specific server products and technologies using the shell.

[NB: For tax reasons, you become a “member” of the organization and go to our meeting as part of that; we don’t sell “tickets.”]
Pricing will range from $750-$950. We’d originally hoped to do a flat price, but the logistics of our venue is pushing this decision. So we’ll be offering discounted tickets first, and then moving up the price as we go. Get in early to get the cheap seats!
If you choose to stay at one of our official hotels, you’ll enjoy a reduced room rate, complimentary in-room Internet, and a short 15-minute walk to the Meydenbauer Center. We recommend taking a shuttle from the airport (http://bit.ly/ZNWGcw $20oneway; taxis $65+) instead of a rental car; parking is NOT complimentary.
NEARBY HOTELS include: Sheraton (http://bit.ly/10mVQog), Hilton (http://bit.ly/YsQiq8), and Red Lion (http://bit.ly/10gXH8v). All are adjacent to each other and are a .6 mile walk to the Meydenbauer Center. Courtyard by Marriott (http://bit.ly/12RvG9a) is across the street from the Meydenbauer Center. We do not yet have official room availability and rates.
These hotels are also less than a 4-minute taxi ride (under $5oneway) to downtown Bellevue, full of retail, dining, bars, and nightlife. You will probably spend MORE on a rental car (around $100 best-case, plus parking fees and fuel).
We will have a small-bandwidth Internet pipe available for WiFi use at the conference center. We recommend that you NOT rely on it for mission-critical or business-sensitive tasks, as it is a shared pipe and will likely have poor performance during peak usage.
We are not currently planning to offer power outlets in rooms. You may NOT stretch power cords across walkways to plug in your laptop. We are seeking out a Power Sponsor - the cost to have enough power for everyone’s laptop is about $20,000 (it’s one way conference centers make their profits), so this is a significant expense.
We are planning a brief private meet-and-greet reception for PowerShell.org, Inc. shareholders. We are also planning general evening events.
MEMBERSHIP SALES WILL BEGIN IN JULY with a private announcement to our 2013 alumni and our shareholders. After that, we will offer a block of memberships to our TechLetter subscribers. These folks will have first dibs not only on the event, but also on our limited block of nearby and discounted hotel rooms. We will release subsequent blocks in 2013 and 2014 for the public.
FULL DETAILS will always be available online at http://PowerShellSummit.org (this will redirect to the appropriate page for information and news).
UPDATE: I know there’s a bit of disappointment that we’re not “on campus.” First… understand that we were a little under-the-radar in 2013, in terms of outside groups doing what we did in those particular locations. We also need to grow the event a bit in order to make it financially self-sustaining. And, the real clincher, no place “on campus” could accommodate us. However, “campus” (this is why I keep putting it in quotes) spans Redmond and Bellevue - we’re actually adjacent to Microsoft offices, in 2014, and we’re scheduling an evening event (community/team mixer, with team Q&A stations) in MS facilities. We’ll also try to wrangle a company store/museum visit (there’s a company Connector Shuttle that runs to Commons, which is where the store and museum are located). Most importantly, our location will ensure team participation - which is what doing this in the Seattle metro was all about. In fact, we’re planning expanded team participation, with the addition of team-led “lightning demos” that will highlight cool features and tricks, and which will be a prelude to that evening’s community/team mixer (so you can ask follow-up questions in smaller groups). So… given all of the possible alternatives, we felt this was the best solution. After all, the main session content is just you sitting in a room - shouldn’t matter where that room is. The big thing for us is the team engagement, and the opportunity to do fun stuff on campus, and we think we’ve got that nailed. More to come.

Bartek Bielawski

Event 3: My way…

Third event is open for voting, but as usual - before I see any of the scripts submitted by you, I’m posting my version. Tried to sneak in few tricks I’ve learned here and there, hope you will enjoy reading and will tell me why I’m wrong. 😉 You can find whole post here.

Boe Prox

Scripting Games 2013: Event 2 Notes

I spent some time last week and this weekend to compile a list of notes of what I have seen with the Event 2 submissions that could show improvement. I touched up on some items with my previous article where I picked out some submissions that I liked and didn’t quite like but wanted to touch on a few more things. Some of this feels like a repeat of last week and even last years games, but that is Ok. This is all about learning and as long as everyone takes what all of the judges have been writing about, then there will be nothing but great improvements during the course of the games. Click here to go to continue reading this article.

Mike F Robbins
Scripting Games

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.
There are also a number of people who are competing in the Scripting Games that are writing blog articles of their own blog sites. A couple of the ones that I’m aware of are listed below and while they’re my competition in the advanced class and have links promoting their Scripting Games entries in their blogs (I do the same thing),  I don’t mind promoting their blog articles because there’s some great information to be found in them. I’m actually glad they provided links to their entries because both of these guys are excellent PowerShell scripters and you could learn a lot from viewing their Scripting Games entries. Ultimately the scripting games is all about the community learning more about using PowerShell best practices in a friendly competition that’s just for fun. 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.
µ

Don Jones
Scripting Games

Changes in Scripting Games Displays

I want to point out some changes that are being made to the Games:
Effective immediately, entry author names and current scores will not be shown for events that are still open for new votes. This is intended to help ensure everyone submitting a score isn’t influenced by other people. I’ve seen a bit of ganging-up that I’d rather not see.
Archived events - those completely closed and for which prizes have been awarded - will display full information, including user names of comment authors.
The new event viewer, which is currently under development, will display comment author names. These will be visible to an entry’s author immediately, and to the public once the event is no longer open for voting.
Entry authors: This means you won’t be able to see your score while it’s still open for voting, unless you use the new beta viewer (which I’ll be wrapping up this weekend).

Don Jones
Scripting Games

Scripting Games beta entry viewer

If you’d like a quick peek at something, log into the Scripting Games Web site, and go look at the entries in Event 1. Your URL should look like this:
http://scriptinggames.org/entrylist.php?eventid=11
Change it to this:
http://scriptinggames.org/entrylist_.php?eventid=11
This is the new viewer I’m building. It isn’t rigged up to accept votes or comments, yet, but I’m working on that. It’s being developed for Firefox; I’ll test the other major browsers once it’s a bit more complete. This is under development, so it may be offline or unreliable. Don’t tell me about it - I’m already working on it .
You can probably use this on Event 2 as well. The voting and commenting should be working. Note that you must vote before you can comment, and right now it’ll only accept one comment per person. That will probably remain the case for the current iteration of the Games based on some back-end dependencies. However, you CAN tie a comment to a particular line number or range of lines, and when viewing the comment it’ll highlight those lines. It’s pretty neat, I think.
Oh, and I know the coloring on block comments is wonky. I need to dive into the color-er’s regexes and see if I can tweak that. Any regex wizards who want to volunteer to help with that, drop me a line. Right now the PowerShell syntax in the color-er is a little primitive. Actually, there are probably several regexes we could add to this to spruce up the listings.
And yes, I know the comments now show the author’s user name. That’s been a big back-and-forth. I’m not a huge fan of anonymous commenting, and right now it’s just your username anyway. Hopefully nobody said anything truly offensive simply because they thought they were anonymous :).
Back to work.