Don Jones

Explore articles and content from this author

Don Jones

372 articles published

3 min read

Why Doesn't My ValidateScript() work correctly?

I’ve received a few comments from folks after my observations on the Scripting Games Event 1. In those observations, I noted how much I loved:
[ValidateScript({Test-Path $_})][string]$path
As a way of testing to make sure your -Path parameter got a valid value, I love this. I’d never thought of it, and I plan to use it in classes. I may write a book about it someday, or maybe even an ode. Seriously good logic. But… I also bemoaned some scripts that provided an additional Test-Path, in the script’s main body of code. Why have a redundant check?
So, first, thanks for the e-mails you all sent. Second… please understand that I can’t respond to you all. I’ve got this full-time job thing, and I’ve got to do it or the grocery store will stop taking our checks. You’re welcome to drop comments here, and I really appreciate when you say stuff like, “can you explain ___ in a future post?” because it gives me ideas to write about. I just can’t get into private e-mail based education for a dozen folks. Teaching is kinda what I do for my job, so most of my time has to go to that.
But - there’s a great teaching point here. Let’s take this example:
valid-default-path
This works as you would hopefully expect. When given a valid path, it’s fine. When allowed to use a valid default, it’s fine. When given an invalid path, it barfs in the ValidateScript. Now look at the next example - which more closely approximates what people have been seeing in their Scripting Games scripts:
invalid-default-path
In the Games, you were given a default path that wasn’t valid on your computer. So folks allowed their script to run with that default, and got errors, and were annoyed that ValidateScript() didn’t catch the problem.
It never will.
When you run a command, PowerShell goes through a process called parameter binding, wherein it attaches values to parameters and runs any declarative validation - like ValidateScript(). That validation will always catch invalid incoming data that’s been manually specified or sent in via the pipeline (for parameters that accept pipeline input). Because my -Path parameter wasn’t declared as mandatory, the validation routine will let me run the script and not specify -path.
Then the shell actually runs my code - and that’s when it assigns the default value to $path if one wasn’t specified on -path. Validation is over by this point, so an invalid default value will sneak by. The assumption by the shell is that you’re providing the default value, so you’re smart enough to provide a valid one. If you don’t, it’s your problem.
So do you just add a second, in-code check for the parameter? I’d still say no. I really dislike redundancy. If you know, because of your situation, that you can’t rely on ValidateScript(), then don’t use it at all - one check should suffice, and if it needs to be in-code instead of declarative, that’s fine. What’d be nice is if there was a declarative way of specifying a default, like [Default(‘whatever’)] that ran before the validation checks, but such a thing doesn’t exist. Frankly, you could probably argue that if you can’t guarantee the validity of a default, then you shouldn’t provide one - and I’d probably buy into that argument, and subscribe to your newsletter.
In this case, the problem is entirely artificial. The default path value given to you in the Games scenario is valid in the context of the Games; it’s just when you test it on your system, outside that context, that a problem crops up.
Hopefully this helps explain how the ValidateXXX() attributes work, and how they interact with other features, like a default value.
Now explain why this will never assign C:\ as a default value:
[Parameter(Mandatory=$True)][string]$path = ‘c:'

9 min read

Thoughts on Event 1 – and, frankly, a rant.

There’s been a lot of dismay floating around the community about the state of “community voting” in the Scripting Games. Some folks are voting without leaving comments (we’ve expanded the comment field to 2000 characters, hopefully that’ll help), and some disagreement about scores.
Disagreement is natural. For example, stick a Write-Host in your script and I’m likely to score you lower. You may disagree, but it’s how I feel in many situations… and I’m seeing a distressing amount of it.
Did you know that using [CmdletBinding(SupportsShouldProcess=$True)] doesn’t automatically and universally make the -confirm switch work? You have to do a bit more.
Did you know that if you put $DebugPreference=‘SilentlyContinue’ in your BEGIN{} block, that you disable the built in -Debug switch’s functionality? Yep, seen this one a few times also.
The community is showing a distinct lack of love for scripts that look like VBScript scripts. Does that mean your script is wrong? No - but it means you’re not approaching the problem in a way that the world in general feels is best. It doesn’t mean your script won’t work - but it means it wouldn’t be widely accepted.
If you’re not happy with your score, look at some higher-scoring scripts. See what they’re doing differently. If you can’t figure it out, post in the forums on PowerShell.org (there’s a Scripting Games forum). Provide the permalink to your script, and solicit some feedback from the community. Tweet people and ask them to take a look. You can ask for more feedback, if you want it and aren’t getting enough.
As our judges begin to post their notes, look at what they’re writing. Maybe they didn’t pick your script to write about - but are they writing about things that you also did in your script?
I’m seeing a lot of good scripts. But I’m also seeing some misunderstandings of some core, advanced features, like error handling, use of Verbose output, and so on. Each of those is a star to a half-star off, for me… some of these things, in my opinion, are severe, and I score accordingly. I haven’t seen a perfect, un-improve-able script, yet (I’m not even halfway through, yet). So no 5-stars yet. But I am trying to leave comments, and I know others are, too, so hopefully folks can improve. But be patient - it takes time.
And opinions differ. Let me offer an example:
Write-Verbose (“Script: {0} ended at {1}” -f $MyInvocation.ScriptName, (get-date) )
****Dislike. Not saying it’s wrong at all - and some people will disagree, vehemently, with me. But I find -f strings hard to read.
Write-Verbose “Script $($MyInvocation.ScriptName) ended at $(Get-Date)”
****For me, that’s easier to read. Not any more “right,” but in my company that’s the standard we adopted and that we use. Now, hopefully my opinion is being balanced by others’ opinions. But, if a substantial number of people share my opinion, this code would get a low score, and a community standard practice would emerge - something we can learn from after the Games are complete. Because yes, I’m going to harvest the Games entries and comments long after the Games are over to help keep the conversation and education going.
My point of this is that none of us are as awesome as we think. Others will always have points of disagreement. What’s really exciting here is the opportunity to create a community consensus of what’s best. That won’t come for several weeks, yet… but it will come. There is zero immediate benefit in getting a high score in the Games, and zero immediate detriment to a low score. This is going to seem harsh, but the Games are not about you. They’re about all of us. They’re about us developing a sense of community involvement and standards in an industry that doesn’t supply many of its own. This will happen over time, and with a lot of effort. But it’s worth it.
Let’s continue.
[ValidateScript({(Test-Path $_ -PathType Container)})]
I love that. I never thought to do that, and I love it. I’ve seen a few people do it. Bless them. I learned something!
An aside: There’s this general undercurrent of, “I wish ’expert’ judges were scoring me instead of the great unwashed masses.” Let me point out some practical realities. One, every entry in the Games at this point has at least 4 votes; many have double that. The last event, most had 1, 2 at most. And yes, while ’expert’ judges are allegedly well-qualified to render judgment, I’m not seeing a ton of scores I completely disagree with, yet. A few. Not a ton. And you want to know a dirty secret? How many entries do you think an ’expert’ can look at, in the evening, after working all day (we’re all volunteers), before he just starts getting a little arbitrary and inconsistent? The number is not “infinite.” I know I got a little arbitrary last year before I caught myself and stopped for the night. So… don’t discount the value of your peers’ opinions. If you’re getting a low score and don’t know why, seek out answers. Yes, people should leave comments with their votes. If they don’t, take charge and seek out answers yourself.
I love that I’m seeing so many divergent approaches to a single (admittedly open-ended) problem. Frankly, the value here is in browsing others’ approaches and picking up some tips from them. Or just seeing something different. You shouldn’t care about your score. You should care about what other people are doing, and about why you think their way might be better, worse, or just different. Make a learning opportunity. Don’t wait for someone to come to you with a free, written analysis of your code. Analyze other people’s entries and judge yourself against their work.
I’ve seen this a few times:

2 min read

Scripting Games Voting Continues!

As of right now, we’ve got almost 1900 votes on entries in the Scripting Games. Remember that each vote is a “pointlet” (see the PowerShell tie-in we did there?), which is basically a raffle ticket in our prize lottery.
But… there’s a secret about the lottery. It’s weighted based on how many entries you’ve voted on.
The algorithm is a bit complex, but for example, if you’ve voted on 90% of the available entries, you’re something like 30% more likely to win a prize. Vote on 50%, and you’re about 12% more likely to win… and so on. It’s a bit logarithmic… as you get closer to 100% your chances of winning increase more and more, with about a 39% advantage if you’ve voted on 100% of the events.
Of course, you can’t just abuse the system. We’ve got automated and manual checks in place for people who are just randomly voting - clicking all the same vote, voting in patterns, or voting with very little time separation between votes. All of those things will trigger a manual review, and you can be banned for life for attempting to game the system. We’re also tracking IP addresses and whatnot, so if you’re voting from multiple accounts, or trying to upvote your own entries… we’re going to just shut you out. You won’t even necessarily be notified, because we’re not confrontational folks.
But I know nobody’d do all that - we’re all in this to make the Games fun and educational! So get in there and vote. And leave comments. If you vote 1-star, tell the author why, so they can improve. Hey, it’s what YOU would want if someone 1-starred YOUR code, right? Right!
So vote! http://ScriptingGames.org!
(PS - please don’t report any tech problems in the comments here. The Games Web site has a feedback link)

2 min read

Meet the Scripting Games Judges: June Blender

June Blender is was a senior programming writer on the Windows PowerShell team at Microsoft from Windows PowerShell 1.0 ““ 3.0. You see her work every time you type Get-Help for the core modules. She’s now working on the Windows Azure Active Directory SDK team, and she remains an avid Windows PowerShell user and a passionate user advocate. She’s a guest blogger for the Scripting Guys and she tweets Windows PowerShell tips on Twitter at @juneb_get_help.
An engineering type by disposition, June was attracted to Windows PowerShell by the efficiency, productivity, and uniformity of automation. As a full-time working mom of three sons (now adults!), the idea of doing anything twice, unless it’s fun, is appalling. When evaluating scripts, she looks for elegance, but prefers scripts that inspire to those that intimidate. If saving a line of code makes your script difficult to understand and maintain, it’s not worth it. The scripts that get a thumbs-up from June are those that reveal a new way of performing a task and can be used as a template for scripts to come. Oh, and they must have Help!
June’s philosophy about Help is pretty simple. It’s supposed to make the task easier ““ clear, complete, and accurate. A parameter description that says that ServerName is the name of the server isn’t worth the characters you use to type it, but neither is the one that says that a parameter retrieves the modification of the nth cell in the hierarchically rarified data structure. She hates passive voice, too, because you don’t know who is supposed to act. About topics are critical. A whole mess of disjointed cmdlet help without an explanation of how they are intended to be used is not really helpful. And the best part of help is the examples. You really can’t have too many (see “Get-Help Invoke-Command”).
Community is the secret sauce in Windows PowerShell, so the best scripts contribute to our shared knowledge, productivity, and fun. June much prefer scripts and functions that you can open, read, and model to compiled anything.
A 16-year veteran of Microsoft, June lives in magnificent Escalante, Utah, where she works remotely when she’s not out hiking, canyoneering, taking Coursera classes, or convincing lost tourists to try Windows PowerShell. She believes that outstanding documentation is a collaborative effort, and she welcomes your comments and contributions to Windows PowerShell and Windows Azure Help.

1 min read

State of the Games

As of Monday at 5pm Pacific time (which is Tuesday morning, 00:00 hours GMT), the 2013 Scripting Games’ first event will conclude. That means the first event is open for community voting - so get on it!
Remember, some of the best prizes - including a free pass to the 2014 PowerShell Summit - are reserved for folks who offer their votes and comments.
Incoming new registrations for the Games will not be able to compete in Event 1 at this point, but they can jump in with Event 2 (and subsequent events) if desired.
We presently have 1100 registered participants - which may include people who just signed up to spectate and vote, as well as our judges. 475 are registered in the Beginner track, 307 in Advanced, and 318 are presently view-only (meaning they’re just voting, not submitting entries). As I write this, we’ve only got 218 entries - but there are still a few more hours to get them in.

1 min read

Forums Migration Schedule

Here’s the schedule for our Forums migration:
From Now until May 4th, the old forums will remain online and in-use. However, you should consider creating an account here on the “new” site (distinguishable by the different visual theme). Your new account will have no connection to the old one, and may be a Twitter, Facebook, Live, or other login. To create an account, just click “Login” at the top-left of any site page (in the dark gray toolbar).
On May 4th we will activate the new forums. From then on, the Forums menu link will go there. The old forums will remain available at https://powershell.org/discuss. You can continue to use the old forums to wrap-up old topics, or if the new ones stop working for some reason.
On May 13th we will shut down the old forums and direct everyone to the new ones.
By May 20 we will have migrated the content from the old forums into the new ones. These will be imported as static threads that are closed for new messages, but they’ll still be searchable.

2 min read

Recording the PowerShell Summit

So, we did have one enterprising fella use his Webcam to record the Summit sessions he attended. Once he gets with me, we’ll get those online so you can see.
We are trying to think really hard about formal recordings for next time. It depends a lot on what folks want. For example:

  • Pointing a camera at the front of the room is easy and cheap. We worry that the audio might suck and that you might not be able to read on-screen code - although many presenters make their code/slides available for download.
  • Putting software on presenters’ machines to capture what they do is out of the question. There are MORE than enough moving parts already going on in the room - this just won’t work out consistently.
  • We can get one-button-recording devices that capture everything the speaker does on-screen, and an audio feed. You don’t get to SEE the speaker, and these are about $1000 each, plus sundry cables and adapters. For several hundred more, we can add a picture-in-picture from a camera feed.

So we can do cheap-o… well, cheaply. And if folks are happy with that, we’ll do it. We can do pretty awesome-looking for pretty-expensive… and that’s going to require a fundraising campaign. We aren’t Microsoft, and recording three rooms, along with possible general sessions, is going to take about $8-$12k in equipment. Our goal, however, would be to give the videos away for free once a year’s event sells to its “break even” attendance point.
Live streaming won’t happen. Meeting venues get like $5,000 per day for a 5-10Mbps pipe. Yeah, you thought they made money off the $80/gallon coffee. We just can’t afford the bandwidth to livestream. We’re not even always sure we can turn on WiFi for people to check e-mail. It’s that expensive.
Please drop some comments. Knowing what kind of video people are willing to accept will really help us plan this out for next time, and we need a lot of lead time to do that.

1 min read

Meet the Scripting Games Judges: "Scripting Guy" Ed Wilson

Ed Wilson is the Microsoft Scripting Guy and a well-known scripting expert. He writes the twice daily Hey Scripting Guy! blog (the number 1 blog on TechNet). He has also spoken at TechEd and at the Microsoft internal TechReady conferences. He is a Microsoft-certified trainer who has delivered a popular Windows PowerShell workshop to Microsoft Premier Customers worldwide. He has written 11 books including 8 on Windows scripting that were published by Microsoft Press. He has also contributed to nearly a dozen other books. He has two Microsoft Press Windows PowerShell 3.0 books: Windows PowerShell 3.0 Step by Step and Windows PowerShell 3.0 First Steps. Ed holds more than 20 industry certifications, including Microsoft Certified Systems Engineer (MCSE) and Certified Information Systems Security Professional (CISSP). Prior to coming to work for Microsoft, he was a senior consultant for a Microsoft Gold Certified Partner where he specialized in Active Directory design and Exchange implementation. In his spare time, he enjoys woodworking, underwater photography, and scuba diving.

2 min read

Now Accepting Nominations for PowerShell.org, Inc. Board of Directors

At our first annual Shareholders Meeting (shareholders will receive an e-mail from me later this week about that meeting), we will be voting on our Board of Directors. Our corporate articles permit our existing Board members to serve indefinitely, and so all are automatically re-nominated. The current Board includes:

  • Myself (Don Jones)
  • Kirk Munro
  • Richard Siddaway
  • Jason Helmick
  • Jeffery Hicks

The Board is responsible for appointing a CEO (which is currently myself) to run the company; the CEO then appoints other officers as needed to conduct the corporation’s business. I’ll reiterate that PowerShell.org is a not-for-profit business, meaning our goal is to more or less break even. We obviously have expenses - Web site hosting, running the Summit, and so on - and the corporation provides a place where the needed funds can be managed, without running through anyone’s personal checking account.
If you would like to nominate someone for the Board, please e-mail president/at/powershell.org no later than May 15th, 2013. Provide the person’s name and e-mail address. You are welcome to nominate yourself.
Each shareholder will receive 5 votes per share owned, and can distribute those votes however they like amongst the nominees. The top 5 vote-earning nominees will comprise our new Board. They will then elect their Chairman, who presides over Board meetings, and either reconfirm the existing CEO or appoint a new one.
If you are interested in becoming a shareholder, please see this post. Note that shares must be purchased before May 1st, 2013, in order to be eligible for voting in the upcoming cycle. We are also nearing the end of our capital campaign, so time is running out to own a piece of PowerShell.org.