O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Working with Script Blocks

The PowerShell programming language is very dynamic. Until now, I have focused on its abilities to manipulate objects of any kind. In this chapter, we will explore my favorite language feature: script blocks. Blocks help craft elegant code not only when manipulating collections of objects but in many other situations. Most importantly, script blocks allow us to encapsulate pieces of code and delay their execution. Script blocks are containers holding pieces of code that do not have to be assigned a formal name. We can create them dynamically in the middle of any script operation, and, of course, we can execute them multiple times, passing different parameters.

You have already seen how you can use them to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required