TLDR – If you are not interested in how the PowerShell script works and just want to jump straight to the solution see the PowerShell script below; just be aware that the script only works when moving a VM to another vNET in the same subscription. To move a VM to a vNET in another subscription you need to follow a different process which will be documented in a future blog post; let me know in the comments if you’d like to see this happen. Moving an Azure VM to another vNET isn’t easy You’d think that since VMs move around a lot on networks that moving an Azure VM from one vNET to another in would be a simple task… it is not. In fact, Microsoft’s official view on this approach is that they do not support it – so this means you are left to figure it out for yourself.
This article specifically address a problem I found when trying to disable archiving on specific folders in Exchange by following Prevent Notes, Calendar and Tasks from getting archived by using EWS script. When running the script I would get the error The UserId in the folder permission at index [xx] is invalid. The rest of this article will assume you have read the linked post and understand it. The Cause The script works by downloading the settings of a user's calendar and adding a "no archive" personal tag to it, it then syncs these changes back to the online version of the folder. Where the problems starts is with the download of the folder; it doesn't just download the folder name, it downloads delegate permissions as well. In my case it wasn't downloading these permissions correctly so I had some blank entries (more on that later). After adding the archive tag it then tries to save the folder settings including the blank permissions resulting in the above error. The fix The above script downloads the user's calendar by calling the bind method on line 50. The default bind command downloads permissions as well. All we need to do is exclude them from