Event 3: My notes…

Time to summarize 3rd event of Scripting Games 2013. I must admin – I learn few new tricks while reading entries for this event. But I still see some things I really can’t stand. Especially in beginner category, where many people decided that putting everything in one line makes it “special”. It doesn’t. If you still think it does – read this article by Richard Siddaway. If you still think line break is cursed – read it again. Repeat. Puszczam oczko

Continue reading

Event 2: My notes…

OK, I’ve seen your entries, and I must say – in general, I like what I saw. But it wouldn’t be helpful to tap you on the back and pretend everything is perfect, would it?

As previously, I will mention few pain points I’ve seen. I will also try to mention what I liked about entries. Let’s jump to beginner category first.

Continue reading

Event 2: My way…

Now that event 2 is closed for new entries – time to let you guys know how I would do it. Again: feel free to complain, comment, judge. I hope I will show you few tricks here and there that will help you with next event, or at least: will help you understand what you might have done wrong. Not that I’m assuming you did, I just noticed few gotchas in this scenario that I wanted to addresses. Have I succeeded? As you probably already know, there is no definite answer to that question. Uśmiech

Continue reading

Event 1: my notes.

Scripting Games is chance to learn things. You can learn by good example, or by mistakes, but often – mistake for one person is perfect solution for other. In PowerShell there are usually many ways to skin the cat, some of those I like – some, not so much. So what did I like and dislike so far? Here are few notes I made.

Continue reading

Supports should process…? Oh really?

I think I blogged about it a while ago, but I still see people who assume that stating that their command SupportsShouldProcess is enough to implement –WhatIf and –Confirm. This is partially true. Namely: –WhatIf part will probably work just fine. Confirm will work fine too most of the time. When it will start to misbehave? When we start to use pipeline, or multiple cmdlets that SupportShouldProcess.

Continue reading

Event 1: My way…

This year judges should focus on blogging. I’ve decided that it may be helpful to give attendees chance to return the favor – I will blog about things I like and dislike in your scripts. At the same time – I will post how I would do it. Feel free to complain, point out mistakes. I will try to post it as soon as entries are closed for submissions, so that I will do it “fresh” before I see any of your scripts – this way I won’t “steal” your ideas. Puszczam oczko

Continue reading

More on output…

It could probably be just yet another comment under “What you see is NOT what you get” post. But I’ve decided I would give it more space and make code more readable than it’s possible in comments.

As I said before: for me nice output is less important than data itself. If I can keep data and make it look nice – I’m more than OK with that. I spent most of my time in PowerShell window so nice output make me happy camper. Winking smile That’s why whenever I write a module I spent some extra time on it to add ps1xml files to it and decide how both Format-List and Format-Table should behave with objects I create. Obviously, objects also have some custom names, usually they have some pseudo-type tattoo rather than type wrote in C# and added to PowerShell with Add-Type.

Problem with more ad-hoc scripting (or scripting in general if module is not an option) in version 2 of PowerShell is that you can’t easily create this custom formatting on the fly. Building ps1xml file is overkill in such scenario, and sending strings to the pipe is something I would rather avoid if original data is something of a different nature (numeric, DateTime, etc.). So, what I would do?

Read more…

What you see is NOT what you get.

While grading scripts in advanced category event 4 I noticed that most people assume that it’s necessary to change number into string to format it nicely. The problem with this approach: once you changed number into string you kind of kill PowerShell ability to sort, filter and group objects based on properties that are numbers. If you ever decide to use it for something else than showing to the user – you will probably have to parse results and reverse whole process. And because it’s PowerShell that you use – you do not really have to. You can get both. As advanced scripter – you should know that already. Smile Let’s take a look at some practical examples, to make it more clear when problems start to show up. If I will sort two objects:

2,10 | foreach {            
    New-Object PSObject -Property @{            
        Name = "Foo $_"            
        Size = "$_ Bars"            
    }            
} | Sort-Object -Property Size            

… PowerShell will try to convince me, that 2 Bars are greater than 10. In world of strings that’s true. In world of numbers – not so much. To be honest – for me that’s huge flaw of that approach. It looks nice, but that’s not usually what I’m after. I want PowerShell to give me information first, look nice later. So what could one do?

Read more…

“Format-{0}”–f ‘List’

Today I would like to write few words about why you shouldn’t work too hard with creating output when PowerShell can do the work for you.

Scripting, as I see it, is a way of taking stuff that “is there” and force it to do my job in a way I want it to be done. If there is something that will do job for me – I will use it. If not – I will create it. So my role is just to build the bridges, not whole road next to the old one.

Obviously, at times you do not know that road already exists. That’s where stuff like Scripting Games help a lot. I for one learned few neat tricks already. But if you fail to see highway and claim to be advanced scripter – be warned, I won’t praise your rocky road that you’ve created next to it. To the point.

Read more…

Hey! Don’t *break* my pipe!

I’m still pretty overwhelmed with number of scripts this year in Scripting Games. While I’m on my “Mission Impossible” I noticed extensive use of break keyword. I commented on it a lot in Beginner 3, but would like to show you why I do not like this as a way of ending your functions and/ or scripts.

I mean, it’s perfectly fine if you use it with what I will show you today in mind, that is: if you want your function/ script to be destructive and break things when you see an error. But if your function/ script is only getting some info from my system and I won’t get full information (like in Advanced Event 2) without admin rights – why do you break things? Isn’t exit/ return enough in such a case…? Smile

Read more…