Script to Move a VM to a New Portgroup and Update its Network Identity
Hey everyone - I recently put together a script to make it easier to move a VM around between various networks. It moves the VM onto the specified Port Group and then uses VMTools to run a PowerShell script in the guest (this is for Windows VMs only, sorry!) to update its IP/DNS/Gateway/etc. Since my old Gist'ing technique isn't working any more, so it's below as simple text (and it's on my GitHub if you want to grab it that way). But first, let's break it down a little bit! The bulk of this script is really straight-forward. The most interesting bit is using the PowerCLI Invoke-VMScript cmdlet to do the work inside the target VM's OS (since this operation will break network connectivity). Invoke-VMScript is, on the surface, similar to the core PowerShell cmdlet Invoke-Command... but they way that they operate is completely different under the covers! The practical difference that made the most impact for me is that Invoke-Command allows access to the par