Powershell: Get object value to int array -
i'm new powershell
can please explain simple way copy values object basic integer array without copying original object.
sorry if confusing, mean want capture object values , put them in integer array can simple arithmetic on values
for example
$computercpu = get-wmiobject win32_processor -computer "mycomputer" | ` select-object {$_.loadpercentage}
on windows server 2008 vm @ work returns 2 values
i want average tried
$average = ($computercpu[0] + $computercpu[1]) / 2
this cannot work values not of type int.
i tried casting values
$average = ([int]$computercpu[0] + [int]$computercpu[1]) / 2
but results in cannot convert error.
i know problem great if explain fundamental solution run problem lot , know there must defined solution or way avoid entirely.
thanks.
ps: if possible please don't provide alternative solution, want know how objects values integer array perform arithmetic on values.
thanks.
in addition ebgreen's answer, use -expandproperty
parameter of select-object
:
$computercpu = get-wmiobject win32_processor -computer "mycomputer" | select-object -expandproperty loadpercentage
the rest of code work then.
Comments
Post a Comment