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
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
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
Thanks for the fast reply.
This works like a charm thanks!
Erik
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
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