Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 1.17 KB

File metadata and controls

40 lines (31 loc) · 1.17 KB

Examples

Complete Example

[CmdletBinding()]
param()

#region Stepper ignore
if (-not (Get-Module -Name Stepper) -and -not (Get-Module -ListAvailable -Name Stepper)) { Install-Module Stepper -Force }
Start-Stepper
# This runs every time. Safe to leave outside New-Step
$outputDir = Join-Path $PSScriptRoot 'output'
#endregion Stepper ignore

New-Step 'Create Output Directory' {
    Write-Host "[$($Stepper.StepName)] Step $($Stepper.StepNumber)"
    New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
    $Stepper.OutputDir = $outputDir
}

New-Step 'Download Data' {
    # Simulate a download
    Start-Sleep -Seconds 1
    $Stepper.Files = @('a.csv', 'b.csv', 'c.csv')
    Write-Host "Downloaded $($Stepper.Files.Count) files."
}

New-Step {
    # Unnamed step (backward-compatible syntax)
    foreach ($file in $Stepper.Files) {
        Write-Host "Processing $file in $($Stepper.OutputDir)..."
    }
}

Stop-Stepper

Because $outputDir is assigned at script level and read inside a step, the first run offers to convert it to $Stepper.OutputDir during cross-step variable review. Accept the conversion, or restructure the example to keep the script quiet.