Public/Unblock-PWSHYBKPIVPin.ps1

function Unblock-PWSHYBKPIVPin {
    <#
    .SYNOPSIS
        Unblocks a blocked PIN using the PUK on a locally attached YubiKey's PIV application.
    .DESCRIPTION
        Wraps "yubico-piv-tool.exe --action unblock-pin". Requires the current PUK and sets a new
        PIN; a wrong PUK still consumes one of the YubiKey's limited PUK retries - and once the
        PUK itself is exhausted, the only recovery is Reset-PWSHYBKPIVDevice, which wipes the PIV
        application - so this cmdlet supports -WhatIf/-Confirm with ConfirmImpact 'Medium'.
        Throws on failure rather than returning a value, matching Unblock- verb convention.

        Accepts the "unblock-pin" action's config-declared options (-Puk, -NewPin, -Reader) as
        dynamic parameters built from Config\Posh-YBKPIV.json.
    .PARAMETER Puk
        The current PUK, as a SecureString.
    .PARAMETER NewPin
        The new PIN to set, as a SecureString.
    .PARAMETER Reader
        Name of the smart card reader to target, when more than one is attached. If omitted,
        yubico-piv-tool.exe uses its own default reader selection.
    .INPUTS
        None. This cmdlet does not accept pipeline input.
    .OUTPUTS
        None. Throws a terminating error on failure; produces no output on success.
    .NOTES
        -Reader is declared dynamically from Config\Posh-YBKPIV.json and therefore does not
        appear in Get-Help's PARAMETERS/SYNTAX sections. Run
        `Get-Command Unblock-PWSHYBKPIVPin -Syntax` for the authoritative, current parameter list.
    .EXAMPLE
        Unblock-PWSHYBKPIVPin -Puk $currentPuk -NewPin $newPin
        Unblocks the PIN and sets it to a new value after confirmation.
    .LINK
        https://developers.yubico.com/yubico-piv-tool/Actions/
    .LINK
        Set-PWSHYBKPIVPin
    .LINK
        Test-PWSHYBKPIVPin
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
    param()

    DynamicParam {
        $dynamicConfig = Read-PWSHYBKPIVConfigFile
        Get-PWSHYBKPIVActionParameter -Action 'unblock-pin' -CmdletWrapping $dynamicConfig.cmdletWrapping
    }

    begin {
        $config = Read-PWSHYBKPIVConfigFile
        Write-PWSHYBKPIVLog -Config $config -Level Debug -CmdletName $MyInvocation.MyCommand.Name `
            -Message 'Cmdlet invoked' -BoundParameters $PSBoundParameters

        $architecture = Resolve-PWSHYBKPIVArchitecture -Architecture $config.installation.architecture
        $exePath = Get-PWSHYBKPIVInstallPath -Installation $config.installation -Architecture $architecture
        if (-not (Test-Path -Path $exePath -PathType Leaf)) {
            throw "yubico-piv-tool.exe was not found at '$exePath'. Run Install-PWSHYBKPIVTool first."
        }
    }

    end {
        if (-not $PSCmdlet.ShouldProcess('YubiKey PIV application', 'Unblock PIN')) {
            return
        }

        try {
            $null = Invoke-PWSHYBKPIVTool -ExePath $exePath -Action 'unblock-pin' `
                -CmdletWrapping $config.cmdletWrapping -BoundParameters $PSBoundParameters
            Write-PWSHYBKPIVLog -Config $config -Level Information -CmdletName $MyInvocation.MyCommand.Name `
                -Message 'PIN unblocked successfully'
        } catch {
            Write-PWSHYBKPIVLog -Config $config -Level Error -CmdletName $MyInvocation.MyCommand.Name -Message "PIN unblock failed: $_"
            throw
        }
    }
}