VMware Cloud Community
heskez
Contributor
Contributor
Jump to solution

NEW vm migrate to different dvswitch and portgroup with powercli expanded

Hi all,

I was wondering if it is possible to achieve this with a powercli oneliner within Vpshere 5?

So far I got this:

get-vds "dvold" | get-vm testvm | set-vds "dvnew" set-NetworkAdapter -Ne
tworkName "pg-new"

This gives me an error message that the migrate cannot be performed.

I've installed the DVswitch addin

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

I think your question can be answered with example 5 of the Set-NetworkAdapter help:

$distributedSwitchPortGroup = Get-VirtualSwitch -Distributed -Name DistributedSwitch | Get-VirtualPortGroup -Name PortGroup
Get-VM VM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $distributedSwitchPortGroup.Name


You can convert this example into a oneliner:

Get-VM VM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName (Get-VirtualSwitch -Distributed -Name DistributedSwitch | Get-VirtualPortGroup -Name PortGroup).Name

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
4 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

I think your question can be answered with example 5 of the Set-NetworkAdapter help:

$distributedSwitchPortGroup = Get-VirtualSwitch -Distributed -Name DistributedSwitch | Get-VirtualPortGroup -Name PortGroup
Get-VM VM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $distributedSwitchPortGroup.Name


You can convert this example into a oneliner:

Get-VM VM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName (Get-VirtualSwitch -Distributed -Name DistributedSwitch | Get-VirtualPortGroup -Name PortGroup).Name

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
heskez
Contributor
Contributor
Jump to solution

Thanks for the fast reply.

This works like a charm thanks!

Erik

0 Kudos
heskez
Contributor
Contributor
Jump to solution

I'd like to expand this script with the possiblilty to type any vm useable for migration.

I get this error

Strings as pipeline input are not supported

$strvm = Read-Host "Please enter the vm name" | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName (Get-VirtualSwitch -Distributed -Name MyDVSwitch| Get-VirtualPortGroup -Name "virtual machines").Name

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

$strvm = Read-Host "Please enter the vm name"

Get-VM -Name $strvm | Get-NetworkAdapter |  Set-NetworkAdapter -NetworkName (Get-VirtualSwitch -Distributed -Name  MyDVSwitch| Get-VirtualPortGroup -Name "virtual machines").Name



Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos