For typical Powershell users writing script vault extensions, the ReadOnlyDictionary class is obtuse to construct, and therefore [SecretInformation] should also supply a constructor that accepts a hashtable or OrderedDictionary and then converts that to ReadOnlyDictionary for the object property.
Alternatively OrderedDictionary could be used, as when it is output to the user as a property the get field could add .AsReadOnly() and you have the same effect of a string,object dictionary. Powershell users already have a shorthand for this and are familar with it: [ordered]@{}
I had to make this function just to accommodate it, so this kind of thing might scare off vault extension authors without a good grasp of .NET
using namespace System.Collections.ObjectModel
using namespace System.Collections.Generic
function ConvertTo-ReadOnlyDictionary {
<#
.SYNOPSIS
Converts a hashtable to a ReadOnlyDictionary[String,Object]. Needed for SecretInformation
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)][hashtable]$hashtable
)
process {
$dictionary = [Dictionary[string,object]]::new([StringComparer]::OrdinalIgnoreCase)
$hashtable.GetEnumerator().foreach{
$dictionary[$_.Name] = $_.Value
}
[ReadOnlyDictionary[string,object]]::new($dictionary)
}
}
For typical Powershell users writing script vault extensions, the
ReadOnlyDictionary
class is obtuse to construct, and therefore[SecretInformation]
should also supply a constructor that accepts ahashtable
orOrderedDictionary
and then converts that to ReadOnlyDictionary for the object property.Alternatively
OrderedDictionary
could be used, as when it is output to the user as a property the get field could add .AsReadOnly() and you have the same effect of a string,object dictionary. Powershell users already have a shorthand for this and are familar with it:[ordered]@{}
I had to make this function just to accommodate it, so this kind of thing might scare off vault extension authors without a good grasp of .NET