Monthly Archives: October 2012

PowerShell $PSScriptRoot vs dot-sourcing

In my previous blogpost I talked about $PSScriptRoot variable Unfortunately there is a problem with that approach and dot-sourcing in PowerShell 2 Imagine we have C:\Scripts\Script1.ps1 C:\Scripts\SubFolder\Script2.ps1 C:\Scripts\SubFolder\Script3.ps1 C:\Scripts\SubFolder\Script4.ps1 Then if you invoke C:\Scripts\Script1.ps1 in PowerShell 3 it is all … Continue reading

Posted in Uncategorized | Tagged | 4 Comments

PowerShell script best practices

I would like to share some ideas that I believe is best practices in PowerShell development Script prefixing In the beginning of all my scripts I add Line 1 – enforcing PowerShell version Line 3 – Automatically implement the standard … Continue reading

Posted in Uncategorized | Tagged | 3 Comments

WTF Method overloads resolution in PowerShell

I have got another WTF! It seems that PowerShell method overload resolution system is not consistent with C# Let’s compare C# vs PowerShell C# will return How we expected But PowerShell will return If we want to have the correct … Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

Indent styles holy wars

It is a probably my Baby duck syndrome but I prefer to develop using indents in Allman style. It also sometime called as BSD Style. In ReSharper indent settings it called BSD style This style is a default recommended style … Continue reading

Posted in Uncategorized | 1 Comment

PowerShell 2 and .NET Framework 4

By default PowerShell 2 is using .NET CLR 2.0. It is quite annoying. I would like to be able to use something like [string]::IsNullOrWhitespace from .NET Framework 4 There are several approaches 1. Modify .NET settings globally saying to use … Continue reading

Posted in Uncategorized | Tagged , | Leave a comment

PoshUnit

I decided to create my own Unit testing framework for PowerShell. I did not like any of that I tried. I am going to implement the following features Portable, which does not require to edit $profile scripts. I want to … Continue reading

Posted in Uncategorized | Tagged | 2 Comments

PowerShell unit testing

I decided to cover all the hooks I wrote with unit tests. For that I tried to find a good testing framework for PowerShell. So far, the only one I liked was Pester – it looks nice BDD framework. It … Continue reading

Posted in Uncategorized | Tagged | 2 Comments