Posts RSS Comments RSS 253 Posts and 393 Comments till now

Archive for February, 2009

How to get the elusive developer license for XenApp

Have you heard stories of the mystical developer license for XenApp, but couldn’t find it?
Have you ever wanted to install XenApp just to test or play with?

These question often plague my readers, but below… below you will find “The Link.” Beware! This is no ordinary link. This is a magical link that will take you on a journey. A journey in which you will find the treasure. The treasure that will finally let you take a hold of this mystical license.

Let the Quest be fulfilled! How to get an eval or a developer license for Citrix XenApp

Functions and why they are important!

I often get asked why I use functions and when I think they should be used. Below is a guide I wrote explaining my theory on functions.


Why use functions?

Functions are, generally speaking, small single task tools (like a flathead screwdriver or hammer.) They do one thing and they do that one thing reliably well. If you take this approach when writing code you will find it easier to debug and find yourself writing less code. Why less code? Because, you’ll find you are now able to port your functions from one script to another or possibly even in your day to day life.

How you decide to write a function?

I have three basic guidelines for when to write a function.

First, if I find I am repeating the same code block over and over (like a code block that checks several services on a computer.) It makes sense to just write a function to perform the check and then run that against each server. This allows me to trouble-shoot the code more efficiently.

Second, if I find that I can use this code in other scripts. For example if I write a nice recursive parsing block. I may want to reuse that logic in another script.

Finally, if I determine the code is useful outside of this script. This may seem like the previous guideline but it is slightly different. A good example here would be a ping-server function. Not only is this useful in other scripts, but it is also useful in my day to day life.

Do you always design functions with the idea of reuse in mind?

Generally speaking it is a good idea to ALWAYS consider reuse when writing code. This is paramount when working with functions. The sole purpose of functions in life is for reuse.  This is major consideration when designing your functions. Consider how and where they will be used. This will help establish what parameters it should have and what (if any) defaults it should have.

What do you put in your functions?

Ideally, because we design code for reuse, it is best to be as verbose as possible.  Basic rule of thumb is hardcode nothing, all data should be passed by parameters. Certainly you can have default values for the parameters, but allow the function caller to specific other options without having to modify the function.  This comes back to the black box approach. One needs to consider the effect of every change the original function and how that will affect the script as a whole.

In v1 I always try to implement –verbose and –whatif with my own switches. In v2 this is handled for you.

Do you separate the logic from the function?

When designing functions one should think about the looping and processing logic. Generally you will find this is script specific and should be implemented outside of the function. Ideally you would want to restrict logic to the party that requires the logic. For example, if you have logic to process servers, keep that logic outside of the functions. There is no need to implement that logic over and over for each function call. On the other hand, if you have logic that is expressly the domain of the function do not go crazy trying to rip it out just to put in the calling script.

What makes a good function?

Great functions are born out of need, but grow out of use. As you grow in your understanding your functions will grow with you. They are like the friend that is always there when you need them, but like that friend they need attention and care. Below are some features that functions should have:

Well defined parameters:

You function needs to be very clear on what data it expects. You accomplish this by having very specific parameters (this often will include the data type as well.) If you absolutely must have a specific value to process make sure that is clear from the function. A great way to accomplish this is by assigning the parameters default value to (Throw ‘$ThisParam is required’).

Consistent and expected output:

This is absolutely critical. You do not want to guess at what data will come from the function. You want the data to be what is expected. Design the function so that it returns one or more of a single data type (i.e. string, DateTime, or Boolean.) Be very cautious not to pollute the data stream with unexpected data written with write-output or data that wasn’t captured in a variable.

Self contained:

The function should NOT rely on any variables from the script. If the function needs input from outside make it a parameter.

Portability:

The single most important job of a function is to be portable. If you do not plan to reuse the code you might as well write the code inline. A key factor to portability is to make sure your variable names will not collide with the calling script. A good rule of thumb is to preface them with $my or $func (like $MyServer or $FuncServer.)

 

Working on a BSonPosh Module for Powershell v2

I am currently working on porting the scripts/functions posted on this blog to a single module download and I need your help. With over a hundred of these on this blog it is clearly going to take some time so what I need from you is what to you think I should port first? I am going to put on the module as soon as I get a baseline (next week or so) and then I will just update it as I go. This means if you have something you wanted added sooner over later, let me know :)

Thanks

My R2/Win7 Experience

I have now been using Windows 2008 R2 for 2 months and Windows 7 client for about a month (two weeks on my production laptop) and I have to say I am thoroughly impressed. I have beta tested every MS OS since 2000 and this is the first time I can honestly say I am excited.

Lets start with Window 2008 R2.
This OS is rock solid. They could release it now and I think it would fair very well. It has enough of a feature increase it is worth the upgrade. I was impressed with 2008 but R2 simply blows it away. It is quicker and I love the taskbar. I am a bit OCD when it comes to my computer and R2 caters to this quite nicely. I wouldn’t be fooling anyone if I didn’t say I was excited about the native Powershell support, but I think that goes without mention. All and all… it is has exceeded any expectations I had. I haven’t had a chance to play with the advance functionality that was introduced, but I plan to get to that this week.

The client…
All I can say is WOW! I think this is first time MS changed the interface in a way that was simply just better. We all know MS has a way of changing the interface that drives people crazy, but this time the changes are relatively noninvasive and worth the aggravation of learning. They truly help efficiency and finally allow keyboard jockeys to put down the mouse and move seamlessly around the screen and apps with keyboard strokes. Some of the new changes seem trivial and just eye candy, but once you get a hold of the usefulness of the new GUI it will change the way you use your computer. GUI changes aren’t the only thing that is noticeable in Win7, the performance is awesome and everything seems snappier. I haven’t got to use the enterprise usability yet, but I hope to get a beta going at work.

Both
The last thing and this goes for both R2/Win7 is User Account Control (UAC.) This was introduced in Vista and while the idea was good, the execution was… ummmm, less than grand. The new OS’s continue down the UAC path (as they should) but have made the process more intelligent and it doesn’t annoy you as much.

The Future
These products are both Beta1 and I would guess a year or so off, but if the final product is even as good as the beta… it will be awesome. Shortly, I hope to start reviewing all the new Powershell cmdlets (+100) soon.

Perhaps Brain should use Powershell (It is taking over the world)

Just listen to a presentation on what the Cluster team is doing with R2… it is amazing.

Here is a little preview
PowerShell for Failover Clustering in Windows Server 2008 R2