Powershell simply doesn't have the concept of immutability as I understand it. You can fake it with custom objects sort of. Here is some code that can be used to fake an immutable hash table:
function New-ImmutableObject($object) {
$immutable = New-Object PSObject
$object.Keys | %{
$value = $object[$_]
$closure = { $value }.GetNewClosure()
$immutable | Add-Member -name $_ -memberType ScriptProperty -value $closure
}
return $immutable
}
$immutable = New-ImmutableObject @{ Name = "test"}
$immutable.Name = "test1" # Throws error
Not my code. It comes from this quite nice article Functional Programming in PowerShell
You should be able to extend this to whatever type of object you want.