Articles

PowerShell articles, tutorials, and guides from community experts.

ScriptingWife
PowerShell for Admins

Charlotte User Group July Meeting

Please join us on a special date in July. This month our meeting will be on July 11, 2013 instead of our normal first Thursday of the month due to the holiday.
Microsoft Scripting Guy Ed Wilson will make a presentation on DSC Desired State Configuration for PowerShell V4.
Sign up at the following link in Meetup so we know how many will be there and we can have adequate food for all.
http://www.meetup.com/Charlotte-PowerShell-Users-Group/events/124356442/

Don Jones

PowerShell Great Debate: Error Trapping

In the aftermath of The Scripting Games, it’s clear we need to have several community discussions - thus, I present to you, The Great Debates. These will be a series of posts wherein I’ll outline the basic situation, and you’re encouraged to debate and discuss in the comments section.
The general gist is that, during the Games, we saw different people voting “up” and “down” for the exact same techniques. So… which one is right? Neither! But all approaches have pros and cons… so that’s what we’ll discuss and debate. In the end, I’ll take the discussion into a community-owned (free) ebook on patterns and practices for PowerShell.

Don Jones
Scripting Games

Overall Winners of the Scripting Games

**Congratulations to our top winners, **determined by our expert judges (and in this case we also considered their CrowdScores), mikefrobbins and taygibb, who have just won a free pass to Microsoft TechEd Europe or Microsoft TechEd North America 2014. Instructions are in your profile for claiming your prize. It is transferrable, but must be claimed/transferred by the end of July.
Congratulations to our top voters/commenters, Klaus_Schulte and Poshsg0606. They were chosen randomly for this award, although I did review their comments and scores to ensure they were all meaningful and consistent. They’ve won free passes to the PowerShell Summit North America 2014; these are transferrable and must be claimed/transferred by the end of July.
Thanks to everyone who participated in The Scripting Games this year. We’ve received a lot of feedback from you, and very much appreciate the time and spirit you spent to offer it. We’re taking it all into consideration for our next event.

Don Jones
Scripting Games

Scripting Games Event 6 Winners

We’re pleased to announce the winners for Event 6 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
Announcements

Call for Debates!

As the Scripting Games begin to wind down, I know that we’ve come across a number of divergent opinions, especially in the comments. “You shouldn’t use .NET classes!” says one comment, “you should have done this with a .NET class” says another comment _in the same entry. _Fun. It’s great to see those differences - but it’d be better to discuss them.
So I’m asking everyone in the Games: Go through your comments on all of your entries. Find comments that you disagree with - but that you could possibly see someone making an argument for (and that you’d perhaps argue against). Post those here as a comment, or email me (there’s a contact form on the Site Info tab). I want to collect these, and start a series of discussions where we can, jointly, start to hammer out some patterns and practices that we, as a community, feel work well. Some of those may have exceptions (rules always do) - “never use a .NET class _when there’s a cmdlet that can do the same thing, _but otherwise go nuts” is one example.
Fire away. For now, you don’t need to put your argument for or against - I’m just collecting the topics that we’ve seen disagreement or differing opinions on. Discussion will follow!
The result of this will be a community-guided Best Practices ebook, which I’ll assemble and we’ll give away for free. I might even build that, initially, as a wiki, so that folks could contribute to it over time. Will see - that’s a bit of extra software.

Boe Prox

Scripting Games 2013: Event 6 Notes

We have finally hit the final event of the 2013 Scripting Games! The past 6 weeks have given us many amazing scripts and some that were in need of extra work. Regardless, for those of you who have finished all 6 scripts in your respective, I say Congratulations! You have hit the finish line sprinting hard to the end! Now you can sit back and know that you made it and have learned (hopefully) some great things along the way. Remember, not only have you learned some new techniques, but also the techniques that you have used have taught others how to write better scripts!
Check out the rest of my notes on my blog here!

Bartek Bielawski

Last events: my notes and scripts.

Oops! Looks like I totally forgot about posting what I did over here. Sorry!
In order of appearance:
Event 5 - script
Event 5 - notes
Event 6 - script
Event 6 - notes
This is last event, and I would like to thank everybody who took part in this games. Thank you guys for great ideas, inspiration, feedback… It was really educational experience for me (as it was in the past), and I hope it was educational for you too. And - congratulations for all the winners. 🙂

Art Beane

Notes for Event 6

When I read the instructions for event 6, I thought that here’s a tough one. A lot of competitors won’t have access to a test environment with Windows Server 2012 and Virtual Machines that they can actually work with. So, I expected that many of the entries wouldn’t get tested and intended to forgive minor errors that would have shown up in testing.
Well, there was one thing that really surprised me. The instructions were quite clear about minimizing “Are You Sure” queries to the user, but you can count on one hand the number of entries that included -Confirm:$false. This is just an example of why it’s so important to read the problem statement very carefully and extract the solution requirements. Then, after creating the solution, go back and verify that the requirements have all been met. Many of the entries called out this requirement in the comments, but then didn’t account for it in the script.
I had mentioned in a previous blog entry that, particularly in the advanced entries, the author was working too hard. Sometimes this means putting more emphasis on “completeness” than in solving the problem. Here’s an example of a wasted effort. A few entries used the [ValidateNotNullOrEmpty()] test for a possible alternate to the default value for “Server”.  Because there is a default value for the parameter, it won’t be null or empty making this test unnecessary. Here, give this a try:

Don Jones
Announcements

More PowerShell v4 and DSC Details

Here’s what I know, much based on a TechEd talk this week:
We can expect PowerShell v4 to ship in the Windows Management Framework, as with previous versions. It will be preinstalled on Windows Server 2012 R2 and what they’re calling Windows 8.1; the default execution policy will be RemoteSigned, and on the server OS Remoting will be enabled by default. Microsoft’s past policy has been “current version and two back,” and if they follow that then we’ll get WMF 4.0 on Windows 7, Windows Server 2008 R2, and later. That would leave out Server 2008, if in fact they follow that same policy.
DSC itself starts with a PowerShell script that’s mainly declarative code: Make sure x is installed, make sure y isn’t installed, etc. PowerShell compiles that into a MOF, which can be transmitted to managed endpoints (computers). The built-in mechanisms for deployment aren’t as complex or flexible as GPO or SCCM targeting, but you could use either GPO or SCCM to deploy those MOFs. That’s the “push” model - you push MOFs out to managed nodes. A “pull” model requires you to configure managed nodes to have a URI and UDDI, and they check that URI for their MOFs.
DSC runs every 15 minutes or every 30 minutes by default, depending on whether you’re using push or pull, and you can configure that time. Right now there’s no feedback or reporting - it’s a bit like GPO, where you push out the setting and it enforces it, but that’s it.
When DSC runs, it takes your “desired state” MOFs and starts running “DSC resources.” These resources are special modules that implement a predefined set of functions - a Get, a Test, and a Set function, to be specific. I expect MS product groups to provide these - the Exchange team will likely someday provide resources that can check/set Exchange settings, for example. You can also write your own modules. DSC calls the “test” to see if your setting is or isn’t configured at that time; it calls the “set” to add/remove/whatever the setting. So the real work is done by these special modules - and those modules can do whatever they want. Write to the registry, run commands, call .NET classes, anything.
So there’s two scripts: The “desired state” script that gets compiled to a MOF (so you shouldn’t ever have to mess directly with MOFs yourself), and the “implementing module” that has the three special functions which actually do all the work.
In the “pull” model, those special modules can be dynamically downloaded by a managed node. “Hey, I grabbed this desired state MOF, and it seems to require 12 modules, so I’ll go to the same URI and look for those 12 modules.” You provide those modules as ZIPs, and PowerShell can grab the ZIP, expand it into the proper location, and then run the modules as needed.
Personal analysis (meaning this is my opinion, not something MS has said): I can see this DSC feature integrating super-well with some future version of SCCM. DSC writes out some local file with configuration details, and the SCCM client grabs it and feeds it up to the database. Those MOFs could potentially be pulled from a Distribution Point by the client, handed off to PowerShell, and run on a scheduled basis. I can also see DSC starting to supplant GPO in a lot of ways. After all, most GPO stuff is just reg hacks in a special section of the registry; there’s no reason DSC couldn’t do that - and it does it on a more frequent basis, making it more reliable. Right now, the targeting of a MOF isn’t as flexible as GPO targeting… but that could obviously evolve. Until more of the architectural details emerge, we won’t know for sure… and this is of course a v1 feature that will doubtless be expanded on and invested in as the team moves forward. We do know that the first release of DSC will not have a lot of those underlying “resource modules,” which means you won’t actually be able to configure much. This is a feature the team needs to put in place so that folks can start building those things… so this is going to take a cycle or two to start being really useful.
There’s obviously still a lot under wraps here, and this is all subject to change and tweaking as the team moves toward release. We’re told there will be some kind of public preview - but they haven’t announced a date on that. Personally, with the Build conference coming up, we can imagine that Microsoft will try and have a preview release ready for that show. There’s also no announcement of ship date. It’s still too early to tell, and I want to emphasize that the company hasn’t announced any dates. We can but try to make educated guesses at this stage.