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 good and works as expected However if you run the same in PowerShell 2 As […]

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 -Verbose, -Debug, -ErrorAction, -ErrorVariable, -Confirm, and -? arguments for you and maybe some other minor […]

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 method called we have to be more explicit about overload we want to call I […]

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 only latest .NET CLR version 2. Modify or create the files powershell.exe.config and powershell_ise.exe.config in […]

Useful git hooks – Part 2

Continuing Useful git hooks Repo – https://bitbucket.org/mnaoumov/githooks/ I completely reviewed the idea of testing hooks You just grab the code from repository, it has only master branch Then you run PrepareForTests.ps1 And it creates local repository and branches to emulate the situations handled by hooks. README.md contains good explanation how to test hooks. Also I […]