This is a nice way to pipe from foreach () without defining a function, and you don't have to use a lot of memory or wait for it to finish:
& { foreach ($i in 1..5) { $i } } | measure
There's actually two kinds of exceptions in powershell, command-terminating (usually pipeline terminating) and script-terminating. After the 2nd script-terminating exception from "throw", you don't get the 'hi' that follows. Both of these would work with try/catch.
1/0; 'hi'
Attempted to divide by zero.
At line:1 char:1
+ 1/0; 'hi'
+ ~~~
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
hi
throw; 'hi'
ScriptHalted
At line:1 char:1
+ throw; 'hi'
+ ~~~~~
+ CategoryInfo : OperationStopped: (:) [], RuntimeException
+ FullyQualifiedErrorId : ScriptHalted
16
u/jsiii2010 Dec 08 '19 edited Dec 08 '19
You don't need @() to create arrays:
Anonymous functions:
triple scriptblock foreach-object:
Combining multiple statements into one pipeline with $(). Also a less often used version of foreach-object.
Using assembly and namespace and popping open a dialog box:
This is annoying. Passing an array to start-job (or start-threadjob in PS 6). You have to add (, ) to the -argumentlist.
This is a nice way to pipe from foreach () without defining a function, and you don't have to use a lot of memory or wait for it to finish:
There's actually two kinds of exceptions in powershell, command-terminating (usually pipeline terminating) and script-terminating. After the 2nd script-terminating exception from "throw", you don't get the 'hi' that follows. Both of these would work with try/catch.
Oh, I didn't realize there was a link, lol.