Wednesday, October 21, 2009

I was creating very simple function today, however got stuck there for a while…

As you can see below, function is very, very simple: Function Global:Security\Encrypt-String ([string]$Input){Return [LoginConsultants.Crypto.Password]::EnCrypt($Input)}

It’s using our library to encrypt some text… To my surprise, it didn’t work however. After a little investigation, it turned out that I made rookie mistake – I used $Input, while it is reserved variable :) Very, very stupid mistake of course, I was just surprised that Posh doesn’t complain if you use such parameter.

Anyway, below is small function you can use to test if parameter you want to use is valid: function Test-ParameterName ([string]$Name) { Return [boolean]$($(Test-Path Variable:$Name) -eq 0) }

As you can see, it’s extremely primitive, only interesting part is Return [boolean]$($(Test-Path Variable:$Name) -eq 0) – meaning of this function is to revert boolean value. So if Test-Path is $True, function will return $False and if Test-Path is $False, it will return $True. I remember that some years ago I used [boolean]$Foo – 1 in .NET, however it is not supported in Powershell itself (operator – is not defined for [boolean] and [int]).

Second, I was reading through a lot of tips and tricks pages. Today I noticed article called 77 Windows 7 Tips. To make long story short, it’s obvious that number 77 was chose first and then they started to think about the content :( Otherwise I don’t see any explanation for some of those tips.

On the other hand, there are other articles that are discussing new features and tips\tricks and are great. To mention just a few of them, Tim Sneath got great article and I also liked a lot article from TechRadar.

So, I decided to write a series of articles about Windows 7. Currently I got 91 tips, but I started yesterday, so it shouldn’t be problem to get to 100. Some of the tricks are really simple and can be explained on 2-3 lines, some will require a lot more space. I don’t want to simply publish tricks, but also explain how some new technologies works and provide some additional details (for example performance comparison of older Robocopy and new one). I will call these articles Windows 7 Maddness and I will try to group tips together.