How it works...
A script block is essentially a series of PowerShell instructions, packaged within curly braces. These allow for a different level of flexibility by having the capability to be assigned to a variable. In this recipe, we assigned a script block to a variable. We do not change anything otherwise, including the parameter we defined in the function. This is to show that a script block is not very different from a function or a script file.
If, at the terminal, after calling the script file with a dot calling operator, you simply run $MyScriptBlock, the output will show the entire script block without the outermost opening and closing braces. This may give you the impression that this is nothing but a string. However, when you ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access