Public/Get-PWSHYBKPIVObject.ps1
|
function Get-PWSHYBKPIVObject { <# .SYNOPSIS Reads raw data from a data object of a locally attached YubiKey's PIV application. .DESCRIPTION Wraps "yubico-piv-tool.exe --action read-object". Read-only - does not support -WhatIf since it makes no changes. Accepts the "read-object" action's config-declared options (-ObjectId, -Output, -Format, -Reader) as dynamic parameters built from Config\Posh-YBKPIV.json. .PARAMETER ObjectId The numeric ID of the data object to read. .PARAMETER Output Path to write the object's data to. Defaults to '-' (stdout) when omitted. .PARAMETER Format Encoding format for the output data: hex, base64, or binary. Defaults to hex when omitted. .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 String[]. yubico-piv-tool.exe's raw output - the object's data, unless -Output redirects it to a file. .NOTES -ObjectId, -Output, -Format, and -Reader are declared dynamically from Config\Posh-YBKPIV.json and therefore do not appear in Get-Help's PARAMETERS/SYNTAX sections. Run `Get-Command Get-PWSHYBKPIVObject -Syntax` for the authoritative, current parameter list. .EXAMPLE Get-PWSHYBKPIVObject -ObjectId 0x5FC109 Returns the raw data stored in object 0x5FC109. .LINK https://developers.yubico.com/yubico-piv-tool/Actions/ .LINK Set-PWSHYBKPIVObject #> [CmdletBinding()] [OutputType([string[]])] param() DynamicParam { $dynamicConfig = Read-PWSHYBKPIVConfigFile Get-PWSHYBKPIVActionParameter -Action 'read-object' -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 { try { $result = Invoke-PWSHYBKPIVTool -ExePath $exePath -Action 'read-object' ` -CmdletWrapping $config.cmdletWrapping -BoundParameters $PSBoundParameters Write-PWSHYBKPIVLog -Config $config -Level Information -CmdletName $MyInvocation.MyCommand.Name ` -Message 'Object read successfully' $result.Output } catch { Write-PWSHYBKPIVLog -Config $config -Level Error -CmdletName $MyInvocation.MyCommand.Name -Message "Failed: $_" throw } } } |