One of the great things about TechEd …

One of the great things about Microsoft’s TechEd conference is the ability to meet different people. Before I began working for Microsoft, I was a consultant and the people I met at TechEd became invaluable sources of expert information. Now that I work for Microsoft, the people I meet at TechEd become invaluable sources of information about what our customers want and need.

A case in point is this weeks Hey Scripting Guy! articles. I heard from several people that they wanted to be able to use Windows PowerShell to write scripts, but that they did not want to learn an entirely new way of doing things. They had VBScripts that worked, but they would like to convert them to Windows PowerShell so they would only have a single scripting environment.

Well, you can certainly do that … it is possible to write Windows PowerShell scripts in the same manner that you would have written VBScript. You can use the same objects – such as the FileSystemObject, and it works exactly the same way that it did in VBScript. In fact, it works even better because you do not need to worry about when you use Set or when you do not use Set.

Is writing Windows PowerShell scripts in VBScript style a “Best Practice?” While there are certainly people that will become quite animated that it is in fact a worst practice, I tend to be more laid back about the situation. Is it more work to write a Windows PowerShell script that acts like VBScript … again it sort of depends. If you must spend 40 – 60 hours learning Windows PowerShell and the “PowerShell way of doing things” … or you spend 2 hours writing a Windows PowerShell script that looks like VBScript … it is easy to do the math.

In reality, what is the “PowerShell way” of doing things anyway? I actually hate this expression. If a script runs, and does not generate any errors … guess what … it is a Windows PowerShell script. I want people to use Windows PowerShell to solve real world problems in their day to day computing environment. I want people to enjoy writing Windows PowerShell scripts, and to feel the pride and sense of accomplishment when they do so without having to download and use someone else's script. I want people to feel free to share their scripts with other people by uploading it to the Scripting Guys Script Repository, and see the script get lots of stars, and plenty of comments from grateful readers who have used the script to solve real world problems.

When I wrote the MSPress Windows PowerShell 2.0 Best Practices book the over-riding principal is a script should be readable. If a script is easy to read, it will be easier to understand. If the script is easier to understand then it will be easier to troubleshoot. Everything else in scripting flows from making the script easy to read. This controls formatting, the addition of comments, the placement of functions, and the use of “magic numbers.” If you understand VBScript, then for you anyway, if the script is readable it is all that matters – it is, after all, your script. As you learn more about Windows PowerShell you will probably want to take advantage of some of the optimizations we have made in the scripting language – but you can begin using Windows PowerShell now. For help learning Windows PowerShell check out the Getting Started articles, and the Scripting Wife articles.