我有一个充满psobjects的数组。现在我想更改数组中每个对象的一些属性。
我的代码:
[array] $objectArray = $null
foreach ($row in $result) {
$object = New-Object -TypeName PSObject
$object | Add-Member -MemberType NoteProperty -Name "Classification" -Value $classification
$object | Add-Member -MemberType NoteProperty -Name "Status" -Value $status
$object | Add-Member -MemberType NoteProperty -Name "Priority" -Value $priority
[array] $objectArray += $object
Remove-Variable -Name object -ErrorAction SilentlyContinue
}
foreach ($co in $objectArray) {
$oldStatus = $co.Status
$oldPriority = $co.Priority
$oldClassification = $co.Classification
foreach ($uid in $resultUids.Tables[0]) {
if ($oldStatus -eq $uid.status_i_d) {
$co.Status = $uid.status_i_d
Write-Host "status" $co.Status "uid" $uid.uid
} elseif ($oldPriority -eq $uid.priority_i_d) {
Write-Host "priority" $co.Priority "uid" $uid.uid
} elseif($oldClassification -eq $uid.classification_i_d) {
Write-Host "classification" $co.Classification "uid" $uid.uid
}
}
}
上面的代码有效,但我不知道如何更改属性本身的值。我想替换" Classification"," Status"的值。和"优先级"与$uid.uid
。
答案 0 :(得分:4)
获取价值:
$co.Classification
设置值:
$co.Classification = "some value"