After the line:
$WMI = GetObject("winmgmts:\\" + $server + "\root\cimv2")
what does @Error return?

You sure that WMI is installed?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.