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. .PARAMETER Share One or more share objects as returned by Posh-SecretSharing's Split-SecretSharingSecret (Identifier, Extendable, IterationExponent, GroupIndex, GroupThreshold, GroupCount, MemberIndex, MemberThreshold, Mnemonic). .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 $lines = @( "Identifier: $($oneShare.Identifier)" "Extendable: $($oneShare.Extendable)" "IterationExponent: $($oneShare.IterationExponent)" "GroupIndex: $($oneShare.GroupIndex)" "GroupThreshold: $($oneShare.GroupThreshold)" "GroupCount: $($oneShare.GroupCount)" "MemberIndex: $($oneShare.MemberIndex)" "MemberThreshold: $($oneShare.MemberThreshold)" "Mnemonic: $($oneShare.Mnemonic)" ) Set-Content -Path $filePath -Value $lines -Encoding UTF8 $filePath } } } |