My Profile Photo

${Graham Beer} = 'blog'


Infrastucture Engineer, PowerShell Developer, WinOps and Automation


The PowerShell scriptblock

The scriptblock is a fundamental feature of the PowerShell language. Understanding the different ways to use scriptblocks is essential to for the advanced PowerShell developer.

What is a scriptblock?
A scriptblock is a block of script code that exists as an object reference but does not require a name. To write a scriptblock we add a piece of code is encapsulated by curly braces {}. Scriptblocks are effectively containers that hold code and allow us to delay their execution. We use scriptblocks for a lot of tasks we do in PowerShell. Consider the following: Where, Foreach, While, Do, to name a few. But we can use scriptblocks for many other cases.

4sysops article continues hereā€¦