Closed DennisL68 closed 8 months ago
That's right. We don't do guess-work. As a result, only object types that are specifically configured get serialized properly. The converters in Metadata are full fidelity, so you get actual objects back, not mock PSObjects the way you would with the Json converter.
As a bonus, we don't serialize your RecoveryPassword in plain text 😒
The good news is it's extensible, and it's very easy to write your own converter, taking into account the desire to encode the recovery password, it might look like ...
Add-MetadataConverter @{
BitLockerVolumeKeyProtector = {
param($_)
[Microsoft.BitLocker.Structures.BitLockerVolumeKeyProtector]::new(
$_.keyProtectorId,
$_.autoUnlockProtector,
$_.keyProtectorType,
$_.keyFileName,
$(if ($_.recoveryPassword) { ConvertTo-SecureString $_.recoveryPassword | ConvertFrom-SecureString -AsPlainText }),
$_.certificateType,
$_.certificateThumbprint)
}
[Microsoft.BitLocker.Structures.BitLockerVolumeKeyProtector] = { "BitLockerVolumeKeyProtector @{
KeyProtectorId = '$($_.KeyProtectorId)'
AutoUnlockProtector = $($null -eq $_.AutoUnlockProtector ? '$null' : "'"+ $_.AutoUnlockProtector + "'")
KeyProtectorType = '$($null -eq $_.KeyProtectorType ? '$null' : $_.KeyProtectorType.ToString())'
KeyFileName = '$($_.KeyFileName)'
RecoveryPassword = '$(ConvertTo-SecureString $_.RecoveryPassword -AsPlainText -Force | ConvertFrom-SecureString)'
KeyCertificateType = $($null -eq $_.KeyCertificateType ? '$null' : "'" + $_.KeyCertificateType.ToString() + "'")
Thumbprint = '$($_.Thumbprint)'
}" }
}
When trying to export properties from my Win 10 BitLocker setup, ConvertTo-Metdata fails to convert the datastructure.
where as, ConvertTo-Json will succeed.