I am struggling to understand why using $args[$i] directly in this command doesn't work. It gives a completely wrong answer.
$memory=$(Get-Process | Where-Object {$_.id -eq "$($args[$i])"} | select -expand VirtualMemorySize64)
However, putting the command line argument into another variable and using that one works.
$id=($args[$i])
$memory=$(Get-Process | Where-Object {$_.id -eq "$id"} | select -expand VirtualMemorySize64)
An explanation on why this is would be great.