idM*_*xCZ 1 powershell edit psobject
我在寻找如何更新现有psobject中的noteproperty的方法,例如,我有psobjects($ a)的system.array:
Group Assigment
----- ---------
Group1 Home
Group2 Office
Run Code Online (Sandbox Code Playgroud)
问题是如何将“主页”更新为其他内容。
$ a | gm:
TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Assigment NoteProperty System.String Assigment=Office
Group NoteProperty System.String Group=Group1
Run Code Online (Sandbox Code Playgroud)
$ a.GetType():
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
Run Code Online (Sandbox Code Playgroud)
多谢您日后的协助。
目前尚不清楚您的问题是什么:选择好的对象或更新其价值?
$col=@()
$props=@{"group"="group1";"assignment"="home"}
$col += new-object pscustomobject -property $props
$props2=@{"group"="group2";"assignment"="office"}
$col += new-object pscustomobject -property $props2
#select object with home assignment
$rec=$col | where {$_.assignment -eq "home"}
#replace the value
$rec.assignment="elsewhere"
#display collection with updated value
$col
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30662 次 |
| 最近记录: |