Cyber Intelligence
Production-Ready Scripts · Reliability

L7. Scripts, Modules, Profiles, and Tooling

Move from one-off commands to maintainable tooling with scripts, modules, manifests, profiles, PSScriptAnalyzer, and a sane folder structure.

Scripts vs Modules

A .ps1 script is a runnable file. A module packages reusable functions, variables, and metadata so other scripts can import them.

New-Item -ItemType Directory .\Protego.Tools
New-Item -ItemType File .\Protego.Tools\Protego.Tools.psm1

Inside the .psm1 file:

function Get-SystemSummary {
  [pscustomobject]@{
    ComputerName = $env:COMPUTERNAME
    PowerShell = $PSVersionTable.PSVersion.ToString()
    OS = $PSVersionTable.OS
  }
}

Then import it:

Import-Module .\Protego.Tools\Protego.Tools.psm1 -Force
Get-SystemSummary

Profiles

Profiles customize interactive sessions. Keep them light. Do not put business-critical automation in a profile because scheduled jobs and CI runners may not load it.

$PROFILE
Test-Path $PROFILE

Linting

PSScriptAnalyzer catches common style, compatibility, and correctness issues:

Install-Module PSScriptAnalyzer -Scope CurrentUser
Invoke-ScriptAnalyzer -Path .\script.ps1

Project Structure

automation/
  scripts/
  modules/
  tests/
  data/
  README.md

Keep scripts, reusable modules, test files, and sample data separate. Future you will be grateful.

Lab

  1. Create a module folder and .psm1 file.
  2. Add one function that returns a [pscustomobject].
  3. Import the module with -Force.
  4. Install and run PSScriptAnalyzer against your script.
Exam Focus Points
  • Scripts run tasks; modules package reusable functions
  • Profiles customize interactive sessions and should stay lightweight
  • Import-Module -Force reloads a local module during development
  • PSScriptAnalyzer helps catch common PowerShell quality issues
  • A clear folder structure prevents one-off automation from becoming unmaintainable
Knowledge Check

1. Which file extension is commonly used for a script module?

2. Why should production automation not depend on your profile?

Recommended: Pluralsight

This free course covers the theory. Pluralsight adds structured video courses, hands-on Azure labs, and timed practice exams to make it stick before exam day.

Start AZ-500 prep free10-day free trial available