Begin, process, end…

Few weeks ago I’ve discovered very strange bug in the way ‘process’ works when used in wrong context. Long story short: someone wrote function with process block, but without begin block. It’s usually OK, but he tried to put some code between param and process block and that gave him error, that is misleading at best:

function Test-BadProcess {            
param ()            
            
# begin {            
$SomeVariable = 'Initial Value'            
# }            
            
process {            
    "Will barf on you! Get-Process does not take scripts! ARGH!"            
}            
}

So how it looks like when you run it?

Read more…