PowerShell 5.1
Is there a way to take a hash or object that contains a secure string password and export it to a file for backup? And restore if needed.
$testHash=@{key1='1';secret=ConvertTo-SecureString -String 'hello world' -AsPlainText -Force}
$sHash=ConvertTo-HashString -InputObject $testHash
$sHash
$SecurePassword = ConvertTo-SecureString $sHash -AsPlainText -Force
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR)
$UnsecurePassword