liveBook · Manning

Recursion

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

Recursion is the repeated traversal or invocation of nested structures through a self-referential operation.

Recursion searches nested folders or organizational units from a higher-level scope. In time-sensitive watcher scripts, broad recursive traversal can process many irrelevant items and reduce efficiency. section 3.3.1

Prefer narrower traversal when the required locations are known:

  • Scope commands directly to the folders or organizational units that contain relevant data. section 3.3.1
  • Use separate watchers for multiple known folders when that is faster than scanning their parent recursively. section 3.3.1

Active Directory watcher

A watcher needed only each site's User OU, not its Computers, Admins, Printers, or Service Accounts OUs. Listing site-level OUs and then querying each User OU reduced execution time from 90 seconds with recursion to 10 seconds. section 3.3.1

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

How deep it goes
Compares recursive and scoped traversal with runtime evidence, but stops short of implementing recursion itself.
Examples
Uses nested folders and Active Directory site OUs to contrast broad recursive searches with targeted queries.
What it assumes
Assumes familiarity with PowerShell cmdlets, folders, subfolders, and Active Directory organizational units.
What you can do after
Apply it via PowerShell by replacing broad recursive searches with targeted commands or separate watchers.
How it connects
Connects recursion with PowerShell cmdlets, folder watchers, foreach loops, and Active Directory organizational units.

Also explained in

Compare how 23 books explain recursion →

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.