2

我有一个充满 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
        }
    }
}

上面的代码有效,但我只是不知道如何更改属性本身的值。我想将“分类”、“状态”和“优先级”的值替换为$uid.uid.

4

1 回答 1

7

获取值:

$co.Classification

设置值:

$co.Classification = "some value"
于 2017-05-10T12:52:20.370 回答