Here's the deal, I'm trying to write a script that will run as a scheduled task. When run, the script checks to see if anybody is logged on. If nobody is logged on, the computer shuts down. I am having no problem using WMI to determine if a user is logged on, my problem is that the shutdown command returns an error of 53. Note: I am testing with restart and not shutdown. Note 2: The task is running with a UserName that is a member of the Administrators group so I don't think the problem stems from an access error.

code:
$a=GetObject("winmgmts:\root\cimv2").ExecQuery("Select * from Win32_ComputerSystem")
For Each $b In $a
If $b.UserName=""
$c=Shutdown('','',0,0,1)
EndIf
Next
$a=0