PowerShell でカスタム オブジェクトのコレクションを作成し、それらをハッシュテーブルに格納しようとしています。問題は、オブジェクトをハッシュテーブルに入れるとカスタム属性が消えることです。
$customObject = New-Object object
$customObject | Add-member -membertype noteproperty -name customValue -value "test"
Write-Host $customObject.customValue
$hashTable = @{}
$hashTable.add("custom", $customObject)
$object = $hashTable["custom"]
$object.customValue = 7
このコードを実行すると、次の出力が得られます。
test
Property 'customValue' cannot be found on this object; make sure it exists and is settable.
At C:\temp\test2.ps1:15 char:9
+ $object. <<<< customValue = 7
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
カスタム属性をコレクションに配置した後、それを使用する方法はありますか?