liveBook · Manning

Building block

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

A building block is a reusable component or capability that can contribute to an automation across multiple development stages.

A building block is a small, reusable automation capability. Breaking a complex task into blocks turns an overwhelming system of logic, systems, and changing requirements into clear goals that can be completed and used incrementally. section 1.3 section 1.3.1

In PowerShell, a building block maps to a function. Give each function one action, so it can be restarted when a failure occurs; place functions in modules so people and other automations can reuse them. section 2.3

Design blocks around distinct operations rather than a whole workflow:

  • Identify the inputs and parameters required for the operation. section 2.1
  • Keep an operation narrow enough to reuse in another phase or automation. section 1.3.1
  • Make a block restartable by having it perform only one action. section 2.3
  • Improve a shared block once and carry the improvement into prior automations that use it. section 1.3.1

Virtual-machine provisioning

Provisioning can proceed in phases: create the virtual machine, install its operating system, and configure the operating system. The creation phase can use separate blocks to select a host, allocate CPU and memory, attach a network interface, and create virtual disks. A subnet-attachment block built during creation can be reused to move the machine to an operating-system deployment subnet and later to a production subnet. section 1.3.3

Figure 1.4 A virtual provisioning phased approach (phase 2) with shared components

This phased provisioning view highlights components shared between virtual-machine creation and operating-system installation. section 1.3.3

Log-file cleanup

A file-cleanup automation can be designed from blocks that find files eligible for archiving, create an archive, and remove archived files. Parameters for the log folder, archive location, archive name, and age threshold make the capability adaptable beyond one run. section 2.1

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Defines the pattern, maps it to single-action restartable functions, and applies it to provisioning and file cleanup designs.
Examples
Uses virtual-machine provisioning with reusable subnet attachment and log-file archiving with configurable paths and age filtering.
What you can do after
Build from scratch reusable PowerShell functions that isolate actions, recover from failures, and can be shared through modules.
How it connects
Connects building blocks with phases, PowerShell functions, PowerShell modules, parameters, and configuration management tools.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.