I ran your script through the editor & it doesn't work.
It dies here: If Exist $mapir + "mapir.dll" with invalid method/function call.
I thought the move command to rename was strictly Unix. It works within Kix for Windows as well? Yes, yes Microsoft has be by the collar.

Thanks,
John