Try querying your local wks by changing this line back to the way you (originally) had it:

$WMI = GetObject("winmgmts:\\" + $server + "\root\cimv2")

maybe try this as a test:

$WMI = GetObject("winmgmts:\\" + @WKSTA + "\root\cimv2")