If the user running the script is a SysAdmin via an AD Group, the function will report they do not have permissions to run the restore process. I'm looking into options to check User is a member any AD Groups with SysAdmin rights