Private/Share/Export-SecretRotationShareFile.ps1
|
function Export-SecretRotationShareFile { <# .SYNOPSIS Writes each Shamir share to its own file - never a single combined file. .DESCRIPTION A file containing every share defeats the entire point of splitting the password: anyone who obtains that one file already has quorum. This function always writes one file per share object, named from its own group/member indices so files never collide even for a multi-group scheme, and never accepts or produces any "all shares" combined output. Each file's content is the share's Mnemonic string and nothing else - no metadata lines - so a file written here can be read back with a plain `Get-Content -Raw` and piped straight into Posh-SecretSharing's own Join-SecretSharingSecret, exactly as that module's own HowTo.md documents for its own exported share files. Earlier versions of this function also wrote Identifier/Extendable/IterationExponent/GroupIndex/GroupThreshold/GroupCount/ MemberIndex/MemberThreshold as extra lines above the mnemonic; that broke the read-back pattern from Posh-SecretSharing's own HowTo.md, since `Get-Content -Raw` on such a file handed Join-SecretSharingSecret the whole multi-line block instead of just the mnemonic. .PARAMETER Share One or more share objects as returned by Posh-SecretSharing's Split-SecretSharingSecret (Identifier, Extendable, IterationExponent, GroupIndex, GroupThreshold, GroupCount, MemberIndex, MemberThreshold, Mnemonic). Only GroupIndex/MemberIndex/MemberThreshold (for the file name) and Mnemonic (for the file content) are actually used. .PARAMETER OutputPath Folder to write the share files into. Created if it doesn't already exist. .OUTPUTS String. The full path of each file written, one per share. .EXAMPLE $shares | Export-SecretRotationShareFile -OutputPath 'C:\rotation-output' #> [CmdletBinding()] [OutputType([string])] param( [Parameter(Mandatory, ValueFromPipeline)] [PSCustomObject[]] $Share, [Parameter(Mandatory)] [string] $OutputPath ) begin { if (-not (Test-Path -Path $OutputPath)) { New-Item -ItemType Directory -Path $OutputPath -Force | Out-Null } } process { foreach ($oneShare in $Share) { $fileName = 'share-group{0}-member{1}of{2}.txt' -f $oneShare.GroupIndex, $oneShare.MemberIndex, $oneShare.MemberThreshold $filePath = Join-Path -Path $OutputPath -ChildPath $fileName Set-Content -Path $filePath -Value $oneShare.Mnemonic -Encoding UTF8 $filePath } } } |