How can I kick out the longest inactive user from a remote machine using powershell 1?
You add the $id incorrectly to the custom object at this line:
$d | add-member -membertype noteproperty -name ID -value $id
Disconnected sessions don't have a session name see:
quser.exe /SERVER:mycomputerUSERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIMEwinfred 2 Disc 4+21:05 2/28/2012 8:38 AM
And require the $columShift, which you have on all your properties, except on the ID Noteproperty. Because of that, you specify the ID incorrectly to logoff.exe, when you are trying to log off a disconnected session.
Instead that line should be:
$d | add-member -membertype noteproperty -name ID -value $columns[2 + $columShift]
Why do this with PowerShell? Use the right tool for the job. In this case, that would be Group Policy.