Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
January 26, 2022

When Is an Array Not an Array?

You naturally want to leverage the PowerShell pipeline when you work with PowerShell. That’s the whole point, after all. The typical pattern is to get a bunch of things with a command, ideally a PowerShell cmdlet or function, and pipe them to another command. The second command consumes the pipeline input and uses it as the basis for its work.

Here is a simple PowerShell function that accepts pipeline input.

Function Invoke-Power {
    [CmdletBinding()]
    Param(
        [Parameter(ValueFromPipeline)]
        [int]$Value,
        [ValidateRange(2,10)]
        [int]$Power = 2
    )
    Begin {   }
    Process {
       Write-Host "Processing $Value to the power of $power" -ForegroundColor yellow
       [math]::Pow($value,$power)
    }
    end {   }
}

Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.