PowerShell Magazine

PowerShell-Magazine-LogoLast week I managed to write few short posts for PowerShell Magazine. It was whole series about XPath. You can think of it as an extension to my earlier post about case-insensitive Select-Xml. And I can’t express enough how different (read: better) this experience was from writing anything for my own blog. Having second pair of eyes (with healthy amount of criticism) made huge difference in the final “product”.

Continue reading

RSAT on Windows 8 works (but fails).


Today – less PowerShell-ish topic, although PowerShell was both used and was main reason I started this journey. Few days ago Windows 8 RSAT RTM went out. Like many other admins I jumped on this wagon as soon as possible. I’ve installed the package and… nothing happened. I haven’t seen any errors yet tools that are part of RSAT where not present on my box. What I did? Obviously, I went to google and asked for solution. But found only few other folks that had the same issue, and many others who installed this package without any issues at all. Something had to be different, but I had no idea – what?

Continue reading

Shell for Windows not Bash for Windows.

I love PowerShell. Literally it saved my behind several times, made my work on Windows 100s more fun than it was before it was shipped (or rather before I tried it and got familiar with all it’s concepts). My first meeting with scripting was bash, but it was long ago, so maybe I will miss some points in this article. But there are so many articles written by *nix experts that tried to jump in opposite direction and were disappointed, that I decided to write this thingy to maybe explain why (in my maybe not very humble opinion) that was the case.

Object in pipe.

All starts there, really. Even if folks understand concept of pipe that passes object all the way, they still try to filter, select and act on strings. It was something impossible for me to avoid in bash. I haven’t done it really ‘hardcore’ way. Only grep, awk, sed, cut, find and xargs. So it was probably just scratching the surface of what *nix shells have to offer. But I’ve seen many times same patterns applied in PowerShell by people who just refused to go all the way and change from thinking-string to thinking-objects. And if there is no grep-substitute some people get lost and blame PowerShell for it. OK, you are probably right, you spent a lot of your time and effort to find out how to play with text parsing and would like to leverage this in Windows in the same way you did on your *nix box. But there are better ways to achieve this goal (I mention it at the end). Powershell is great for filtering, but you have to see objects, even if there is text. And use cmdlets *designed* for filtering. Where-Object is very powerful and can work both with string and with full objects. So no: “Out-String | Select-String” please…

Console is not PowerShell.

Another very common mistake I see is assuming that ‘blue box’ is Powershell. Full stop. I agree that ‘blue box’ is very limiting at times. It also has many ‘features’ that may drive people crazy. Like selecting text inside it, all that ‘Quick Edit’ modes, size that does not scale unless you tweak it using $host variable, limited number of fonts to select from… List goes on. Mine favourite ‘feature’ is Tab-killer (best option to get rid of everything after cursor is to press tab 😉 ). But there are at least 3 other hosts available for free (one out-of –the-box on Client machine and as optional feature on server). All do better job in my opinion. And there are some commercial alternatives that probably do even better than that. I personally use ISE, PoshConsole from time to time, and there is also PowerGui script editor, that can serve as console window too (greatly improved in version 2.4). If you don’t like powershell.exe – just stop using it. But don’t pretend to be powershell expert if all you did was launching this blue box and looking at features of host. Powershell is engine that maybe used in many hosts, including old and not very smart ones, like [system.console] 😉

Pain of growing too quickly.

Another thing I would like to point out. It’s unfair to compare something mature and improved over last 30 years with stuff that is still not full-featured yet. As Jeffrey Snover keeps saying all the time: Microsoft is digging itself out of the big hole, and it takes time. I would imagine it also forces PowerShell team to make some painful decisions: we won’t make this, this and that in this release. And now when PowerShell is a part of Windows as a whole the release cycle is tied to OS cycles. It forces us, PowerShell users, to wait longer for new improvements. Good part is that PowerShell team did a great job to make it possible (and pretty easy too) for community to extend functionality of PowerShell. Many requests I’ve seen from *nix folks were implemented long ago by creators of PowerShell Community Extensions (pscx) but still, some things that we (users) and team (trust me on this one) would like to see in PowerShell will take a while to complete. It does not mean that we can’t do it ourselves already (I hope to find out HOW during TechEd next week, there will be session that I simply can’t miss exactly about that) – it means that we can’t assume given functionality is available on every box, and of course it makes our life harder (WE need to check if given module is installed on box). But the fact that we can prepare some really wonderful extensions without asking Microsoft to do it makes it really great. But to have mature product – we need more time. I will wait, I’ve already see it’s worth it.

Different world, different shell, different mind set.

I’m windows admin for quite some time. Do you know how often do I need to parse text to solve tasks? My world is built of objects. Even text is build of objects. I need something that simplifies working with objects and makes it possible to automate object creation, usage and recording (as text, obviously, I can not read anything else unless it’s image). Folks from *nix part of the world come to windows and want to have something, that would improve their life inside it. They assume shell is only good if it’s built on text parsing, because they are used to that kind of shell scripting. Seen comments that ‘cp’ is obvious command (oh really…?). Sorry guys. You are obviously trying to convince world, that only because you spent time and learned by hard all commands and patterns from *nix shells, than Windows shell should follow same rules. I see reason why this assumption is made. When you see ‘ls’, ‘cat’, ‘cp’, ‘rm’ – you may start to think that this is just bash-clone on windows box. And it’s not the point: all those aliases are created only to allow shell users (both cmd and bash) to use some commands that we already have in memory. No way ‘cp’ is more obvious than Copy-Item. If I have no idea what Select-String does I can guess. Try guess what poo command would do? Or huhu command? And what about Get-Elevator? Show-Picture? We have many objects, our world is too complicated to study by hard all shortcuts that team producing some functionality thought were cool and easy to remember. That’s were PowerShell saves our back. We can do lucky guesses, we can Get-Command, Get-Help, we can push object all the way and Get-Member, make lucky guesses on that members too. And move on. Really, something that I would like to see everywhere.

Get-Kid | foreach { $_.Feed() } # done with breakfast 😉

Bash on Windows box.

Now last point. If you really want to use your bash skills when you manage Windows – you can. It’s there for quite some time, and it works fine (and I won’t argue if that is better option than Powershell – for sure it’s different). Don’t try to convince world that PowerShell has to be bash-clone. It shouldn’t be. If all you need is bash on windows – use it there. Never tried myself, but there are many folks who did Cygwin + bash and are more than happy with that couple. You may complain that it is not there by default. But why should it be? And wouldn’t part of *nix experts that spell MS as M$ complain, that Microsoft is ‘stealing’ again? I’ve seen such comments even for aliases in PowerShell. If they moved that far with something that was designed to make start in PowerShell a bit easier for people who are used to work in bash – how far would they go if Microsoft would decide to have both bash and PowerShell side by side as two alternatives? I will do easy guess: they would barf on M$, complain about it, and in the end – install cygwin + bash themselves, because there has to be something wrong with version shipped with Windows and updated using Windows Update, WSUS or SCCM. After all it’s M$, right? 😉

First entry. ;)

I’ve tried to start blogging several times in the past. Always failed. Mainly because I don’t really like to write to everybody out there – this way it seems like writing to nobody. Nobody reads, nobody cares, nobody notices. 😉 I hope this time it will be different. at least on my side. It may happen that again: nobody will ever read any of my blog-posts. But I decided that this time I will try to be more technical. Which means that it may happen, that my blog posts will help others solve their problems. Or help them realize that they do have a problem that they haven’t noticed before. 😉

I’m IT person so I will focus on IT problems that I come across. I’m also script maniac, been writing scripts for years now. Mainly in the windows environment. I’ve been using cmd for many, many years. Until I’ve wanted to check batteries status within our location. 100+ laptops… Googled it, as usually. And got some simple query using something named “PowerShell”. I knew there was WMI out there, I knew there was VBS too. But I simply liked the idea of interactive shell. And here it was: WMI, VBS and shell in one. “One to rule them all”, came across my mind. And now I’m trying really hard to become Lord of the Rings. 😉

Meanwhile I had chance to participate in VBS + WMI training and I really enjoyed both the training and writing scripts in VBS. But life was never same again… 😉 I’m PowerShell addicted now, and write both VBS scripts (in areas where it would be possible to share it with others in my organization) and PowerShell scripts/ one-liners – for myself. 🙂 I also like to do things that can be done GUI-way in PowerShell directly, just because it’s quicker and more consistent than to click my way thru GUI interface.

Why in English? Mainly because I use EN_en at work. If I do something in IT area I usually think in English. 😉 So even though my English is not as good as I would like it to be, I don’t see any other option.

This is first post. Hopefully not the last one. 😉