17
Scripts, Functions, and Script Blocks
In PowerShell, scripts and functions are commands. They have overlapping capabilities and often only differ by common use.
Scripts tend to be used to implement well-defined processes; such scripts often run on a schedule of some kind. A script may include functions or run other scripts, and will often use commands from other modules. A script is convenient as it consists of a single ps1
file.
Functions can be used to implement a single process in the same way as a script. A function might be part of a script, implementing a process, or part of a module. When automating a process, writing a module to host a function might be regarded as slightly less convenient and less simple than writing a script.
Get Mastering PowerShell Scripting - Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.