Hash files in parallel with throttled runspaces

PowerShell
# PowerShell 7+: hash every file under a folder in parallel.
function Get-FileHashes {
    [CmdletBinding()]
    param(
        [string] $Path = '.',
        [int] $ThrottleLimit = 4
    )

    $files = Get-ChildItem -LiteralPath $Path -File -Recurse -ErrorAction Stop

    $files | ForEach-Object -Parallel {
        $hash = Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256
        [PSCustomObject]@{
            File = $_.Name
            Hash = $hash.Hash
        }
    } -ThrottleLimit $ThrottleLimit
}

Get-FileHashes -Path . -ThrottleLimit 4 | Format-Table -AutoSize