Are you sure that you have share level and NTFS permissions on $sharename1 and $sharename2? That's probably where the error is. You might have to check with an Admin to ensure that the user running the script has the appropriate access to browse to the UNC (Windows browsing through Explorer, not browsing with IE, they are two different animals).