更改 psobject 的值 属性

Change value of a psobject property

我有一个充满 psobject 的数组。现在我想更改数组中每个对象的一些属性。

我的代码:

[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
        }
    }
}

上面的代码有效,但我不知道如何更改 属性 本身的值。我想用 $uid.uid.

替换 "Classification"、"Status" 和 "Priority" 的值

获取值:

$co.Classification

设置值:

$co.Classification = "some value"