I dont think this line here is working properly, its returning an empty object:

$folder=$shell.namespace($folder)

? VarTypeName($Folder)

-Shawn