These lines here ...

$System = CreateObject("Kixtart.System")

You have a few of them ... usually best pratice to only declare $system once, at the top of your script. Shouldnt really need to declare it multiple times.

-Shawn