如何在powershell中创建只读成员



当我在Powershell中使用Add-Member cmdlet时,如何使成员只读?

基本上,我想为具有只读属性的System.Diagnostic.Process添加一个成员

像这样:

 $p = new-object System.Diagnostics.Process
 $p | Add-member -Name thisisreadonly -membertype scriptproperty -value { 6}
 $p.thisisreadonly #gives 6
 $p.thisisreadonly = 5 #error- Set accessor for property "thisisreadonly" is unavailable.

也就是说你创建了一个ScriptProperty,只有getter没有setter

最新更新