5 Replies Latest reply on Aug 1, 2020 12:07 PM by LucD

    VM portgroup to another portgroup

    fborges555 Enthusiast

      HI gurus

       

      I need to change around 100 VM from one portgroup to another portgroup, is this possible using PowerCLI

       

      Thanks in advance

        • 1. Re: VM portgroup to another portgroup
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors
          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: VM portgroup to another portgroup
            fborges555 Enthusiast

            L.

             

            Thanks I got this far, do you think i am in the right direction

             

            $vm='myvmtomove'

            $destination='myesxihost'

            $Datastore='myDatastore'

            $destinationPortG='PortgroupLabel'

            $networkadapter=get-networkadapterr -VM $vm

             

             

            move-vm $vm -destination $destination -networkadapter $networkadapter -portgroup $destinationPortG -datastore $datastore

             

            this will move the vm to another esxi host on a different cluster and change the VLAN ID for destination and datastore also as well

             

            let me know if I am close

            • 3. Re: VM portgroup to another portgroup
              LucD Guru
              User ModeratorsCommunity WarriorsvExpert

              I thought you just wanted to change the Portgroup for each VM.

              Not sure why the Move-VM is there?

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: VM portgroup to another portgroup
                fborges555 Enthusiast

                L.

                 

                My bad on making this clear

                 

                I have vms that I want to move them from one cluster to another new cluster within the same data center , also I would like to move them to a new datastore and to a new portgroup within the new cluster , I thought I could use the move-vm to accomplish this as I used this move-vm to move between cluster and different datastore, I hope I make sense now.

                 

                Thanks

                • 5. Re: VM portgroup to another portgroup
                  LucD Guru
                  vExpertUser ModeratorsCommunity Warriors

                  Ok, can you try something like this?

                   

                  $fromCluster = 'oldCluster'

                  $toCluster = 'newCluster'

                  $newDatastore = 'newDatastore'

                  $newPortgroup = 'newPortgroup'


                  Get-Cluster -Name $fromCluster | Get-VM |

                  ForEach-Object -Process {

                      Move-VM -VM $_ -Datastore $newDatastore -PortGroup $newPortgroup -Destination $toCluster -Confirm:$false

                  }

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz