Articles

PowerShell articles, tutorials, and guides from community experts.

June Blender

PSCustomObject: Save Puppies and Avoid Dead Ends

Welcome to Scripting Games 2013. Here’s my favorite hint for improving your functions and scripts. Avoid writing to the console or formatting your output. Instead use PSCustomObject in Windows PowerShell 3.0 and leave the formatting to the end user.
Windows PowerShell provides lots of great ways to return the output of a command or function. You can write to the host program (Write-Host), write to a file (Out-File), and format your output to look really pretty (Format-*). But all of these techniques kill puppies and bring the pipeline to an abrupt halt.
“Puppies?,” you ask. Yes! Windows PowerShell MVP and Scripting Games 2013 Viceroy Don Jones (@concentrateddon) famously says that every time you use Write-Host, a puppy dies. So sad!
The Format cmdlets are almost as bad, although no deaths have yet been attributed to them. Instead, when you use a Format cmdlet, a huge STOP sign should appear warning you that you’ve brought the pipeline to a halt. Not technically, of course, but for all practical purposes.
To see what I mean, take a peek at these two commands. The output of these commands looks very similar, but it’s really quite different.

Don Jones
Announcements

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.

Don Jones
PowerShell Summit

Summit Downloads

We’ll be updating this post as presenters turn over materials to us. Most of these files will be ZIPs. If there are any session materials missing - please be patient (we’re uploading as quickly as we can), or contact the presenter directly (as they may not have provided materials to us yet).
Driscoll AST Manipulation
Prosser WrappingBinaryModule
Creating HTML Reports with Style PSHSummit
Wrock Unit Testing Powershell.pptx
Brundage The Powers of PowerShell Pipeworks.pptx
Don Jones All
Slides from Several Speakers in one ZIP
Renouf BothSessionsAndExampleScripts
Hicks How Secure Can You Be.pdf
Hicks Look No WinForms
Team - PowerShellSummitNA2013 - WinRM Drilldown.potx
Shirk FasterPowerShellTalk
Ricardo’s Device Mgmt talk
Bunch more - should be the rest of them
Ian Davis has his at https://github.com/idavis/PowerShellSummit
Here is the link to Ricardo Mendes"™ Device Management PowerShell module he mentioned during his session. http://gallery.technet.microsoft.com/Device-Management-7fad2388

Poshoholic
Announcements

[UPDATED] PowerShell Summit 2013 Conference Schedule

If you are attending the PowerShell Summit next week in Redmond, you might want to make sure you have copies of the schedule on hand.  There are two tracks, and I have created two pdf documents, one for each track, that provide the full schedule including session abstracts and speaker bios.
PowerShell Summit 2013 Conference Schedule - Track 1
PowerShell Summit 2013 Conference Schedule - Track 2
While those details are very useful, some of the conference attendees have expressed an interest in having a consolidated view of the agenda so that they could see which sessions were taking place on each of the tracks and choose which they were more interested in.  Ask, and ye shall receive.  Here is a consolidated view of the conference sessions on all tracks, with each day on a separate page.
PowerShell Summit 2013 Conference Schedule - At at glance
Note that if you don"™t have a ticket for the conference, it is sold out for this year.  We"™re planning the 2014 conference now, so keep watching this blog for news about that conference as it becomes available.  There are already a few posts about it that are worth reviewing if you missed them.
Thanks, and enjoy the conference next week!
Kirk out.

Don Jones
Scripting Games

Meet the Scripting Games Judges: Jeffery Hicks

Jeffery Hicks is a Microsoft MVP in Windows PowerShell, Microsoft Certified Trainer and an IT veteran with over 20 years of experience, much of it spent as an IT consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency.He works today as an independent author, trainer and consultant.Jeffwritesthe popular Prof. PowerShell column for MPCMag.com, is a regular contributor to the Petri IT Knowledgebase, 4SysOps and the Altaro Hyper-V blog, as well as frequent speaker at technology conferences and user groups.

Don Jones
Scripting Games

Advanced Practice Event

I want to direct your attention to this forums post, which I think is worth anyone’s time to look through. I’ve left a pretty long reply with some comments on the entry that would also be worth a read.
I find that a LOT of folks - like the gentleman who posted his script - have a really good approach to PowerShell scripts. They want to use parameters. They want verbose output. They want to proactively check for errors. Where I think folks get lost is in the fine points of how PowerShell enables these features. I see folks working harder than they need to, coding functionality that the shell will actually give them for free. I also see some not-entirely-perfect approaches to things like parameters and error handling, and some occasional mis-use of advanced features (I often see SupportsShouldProcess declared but not actually implemented).
Sometimes, this simply happens because a lot of these advanced features aren’t well-documented in one convenient spot - they’re all spread out - and because folks are learning from blog posts, which may themselves have been written by someone with an incomplete understanding. Or, they’re pasting bits together without really knowing what they’re doing. That’s cool - what you have to sometimes do is take a whack at something like this poster did, and get some feedback. I’m really glad he did, because it offers an opportunity to clear up some misunderstandings, which will just make his scripts even better in the future.
I hope everyone’s looking at the Games as a learning opportunity. I hope everyone will vote on folks’ entries and leave comments when they do; I hope as many people as possible spend some time blogging about what  they see, what they’ve learned, and what they don’t understand. That’s how we’ll all improve.
Let me give you a perfect example (we’re no longer discussing the forums post, here - I’m moving on to a new topic):

Don Jones
Scripting Games

Show Your Scripting Games Pride!

If you’re participating in the Scripting Games, log on to the Scripting Games Web site and check out your Profile page. You’ll find a redemption code that can be used to unlock a Participant achievement on the main PowerShell.org Web site!
FirefoxScreenSnapz001

Don Jones
Announcements

Comments from the PowerShell.org survey

As you probably know, we’ve been running a survey for PowerShell.org, which helps us both improve the site and create demographic information that makes us appealing to sponsors (who, you know, pay for everything here). We’ve gotten a ton of great feedback. Yeah, we really are reading every single comment you left.
Let’s start with the biggies:

Maybe some more guest writers for articles? I imagine it’s difficult with all the articles that get posted all over the net every day, but maybe some of those folks (like the scripting guys or scripting wife) can do some to help the Powershell.org community.

Don Jones
Scripting Games

Beginner Practice Event

As you may be aware, we posted Practice Events for the 2013 Scripting Games, in an effort to give people an idea of what the events would look like and involve. There’s been a lively discussion in the PowerShell.org forums about the Beginner Practice, so I thought I’d weigh in. Here’s my solution:
Beginner practice event
Of course, that’s hardly the only way to go about it. I used this approach because it minimizes the use of extra variables, and doesn’t create a script-style approach - it’s a “one-liner,” although I’ve broken it across several physical lines for readability. I think it makes good use of PowerShell’s native ability to deal with multiple objects in a stream - there’s no need for a ForEach loop, here.

Don Jones
PowerShell Summit

[UPDATED] Last-Minute Summit Info and Changes

Please make sure you’re following this announcements category as you travel to, and attend, the Summit. It’s the best way for us to get out late-breaking news.

Registration begins at 8am on Monday, April 22nd, in the lobby of Building 40. Now, sometimes the lobby doors open a wee bit late - so bear with us. The first sessions aren’t until 9am, so there’s plenty of time. Please bring a printout of your ticket from EventBrite, and a photo ID.
Session pre-registration didn’t happen - we had some volunteers have emergency health issues that just got us behind schedule, so we couldn’t get the mobile app thing going. No fear. Sessions will be on a first-come, first-seated basis. Note that we are spread between two adjacent buildings, so you may have to traipse from one to the other during the 15-minute session breaks.
Meals will include a very light continental breakfast and a lunch. We will endeavor to supply soft drinks throughout the day, but that will require Microsoft employees to shuttle them to us. You’re welcome to bring your own soft drinks. We’ve got coffee lined up. Please respect your fellow attendees - we’ve ordered enough food for everyone, but that assumes everyone’s taking a normal-sized serving. A plate piled high with croissants isn’t normal, and deprives your fellow attendees of their share. Seriously - this happened at a conference I was at a couple of weeks ago. Pretty sad.
Kickoff we will have a VERY SHORT kickoff in each session room at 8:45am. We’ll endeavor to present all general material in both session rooms, since neither room can accommodate all of us at once. Jason Helmick and myself will be handling those duties throughout the event. You’re welcome to come to us with any problems you run into.
Problems may arise - bear in mind this is our first year, and just be patient with us. If you bring it to our attention, we’ll fix what we can, as soon as we can. We really appreciate your help and patience as we try to make a great event!
Wi-Fi is not guaranteed, and we will not have power drops for everyone’s laptop. Please do not stretch your laptop power cord across any walkways - you will be asked to unplug for safety reasons. We suggest leaving the laptop in your hotel room, so help make the room more comfortable for everyone (if everyone brings a laptop and a giant bag for it, it’s going to get cramped).
Parking is limited on-site, and you need to make sure you park in a space that isn’t restricted. Check-in with the building receptionist to see if your car needs to be registered. You can also park at the ExtendedStay America hotel across the street, and walk to buildings 40 and 41. You’re responsible for your own transportation during the event.
Evening events are strictly on-your-own. We don’t have anything official planned. If someone puts something together ad-hoc and tells us, we’ll do our best to spread the word.
This is an informal event - don’t think of the Summit as a conference like TechEd, but rather as a gathering of friends and colleagues. It’ll be less structured, more ad-hoc, and hopefully more engaging.
Please be respectful of speakers while they present, and follow their guidelines on when to ask questions. We do have to push them off the stage at the end of their allotted time, so give them their time to complete their presentation for you. If you have additional Q&A after the session ends, please take it into the lobby so that the next session can start.
MONDAY AT LUNCH we will launch the 2013 Scripting Games with an EnergizedTech opening ceremonies video. It’ll be a pageant - don’t miss it. 12:30pm in each session room.
WEDNESDAY AT LUNCH in the lobby or session room in building 40, you’re invited to meet the Summit organizers (if you’ve managed to avoid us until then) and offer feedback for 2014.