Skip to content

PowerShell

PowerShell quirk 2

tl;dr Let's say you have a File[1].txt file and you would like to read it. Get-Content "File[1].txt" ^ this returns nothing Why? PowerShell interprets [] as special characters. A range in this case. PowerShell is actu...

PowerShell Gotcha! - dynamic scoping

PowerShell uses dynamic scoping. Yet the about_Scopes page doesn't mention the word "dynamic". Wird (wird - so weird that you need to misspell weird to get your point across). tl;dr; In PowerShell variables are copied...

Environment variable

but only in a specific directory The idea - use the Prompt function to check if you're in a specific dir and set/unset an env var: function Prompt { $currentDir = Get-Location if ("C:\git\that-special-dir" -eq $curren...

PowerShell "Oopsie"

Task - remove a specific string from each line of multiple CSV files. This task was added to the scripting exercise list. First - let's generate some CSV files to work with: $numberOfFiles = 10 $numberOfRows = 100 $fi...

PowerShell quirk

tl;dr In PowerShell if you want to return an array instead of one element of the array at the time do this: > @(1..2) | % { $a = "a" * $_; @($a,$_) } # wrong! will pipe/return 1 element at a time > @(1..2) | % { $a = ...