Try replacing:
$lvl = $res.notificationlevel
with:
[int]$lvl = $res.notificationlevel
Given you're output if it hit's the default statement from your switch, it doesn't return a number.
Output: ==============================================
Message.WinUpdates: Windows Updates status couldnt be determined
Statistic.WinUpdates:
Running with the updated line outputs a '0':
Message.WinUpdates: Windows Updates status couldnt be determined
Statistic.WinUpdates: 0
Update: As well, your last line return an exit code of $lvl, and if it isn't a value of 0, the SAM element will go into a down state and you will receive the "Get Output Failed" message.