I hit my head against the wall on this one. I know that if I create an Array in Powershell, then copy the array, it will copy it as a reference type, not a value type.
So a classic example:
$c = (0,0,0) $d = $c $c[0] = 1 $d 1 0 0
The solution is to make $d = $c.clone() This does not work, although the array itself is a collection of reference types. That's my problem. I am trying to create an array to track CPU usage by creating an array of processes, wait a while, and then check the latest values ββand calculate the differences. However, Get-Process creates a reference array. Therefore, when I do the following:
$a = ps | sort -desc id | where-object {$_.CPU -gt 20}
$a and $b will always return the same value. If I try to make one record at a time using something like $ b [0] = "$ a [0] .clone ()" - PS complains that the clone cannot be used in this case.
Any suggestions
Also, only FYI, the second line $a = PS |.... is not actually needed, since $a is the reference type for the PS list object, it is actually updated and returns the most recent values ββwhenever $a called. I have included it to clarify what I am trying to accomplish here.
source share