VMware Cloud Community
vmstoani
Contributor
Contributor

migrate vm from vds to vss

Hello,

Need help for this script.

I have to migrate a lot of VMs from vDS to vSS.

I'm using the following script which does not work.

When starting the script vCenter logon is ok, but then the script do nothing.

No errors

$cred = Get-VICredentialStoreItem -File "D:\Scripts\Credentials\credentials.xml"

Connect-VIServer -server $cred.host -User $cred.User -Password $cred.Password

# Read Input File

$InputFile = Import-CSV "D:\Scripts\NETWORK\ARS-OFM.csv" -Delimiter ';'

# Parse the input file

ForEach ($Network in $InputFile) {

    $Clustername = $Network .CLUSTER

    $vSwitchname = $Network .VSS

    $NEWVLANname = $Network .VSSPG

    $OLDVLANname = $Network .VDSPG

    $VLAN = $Network .VLAN

# Retrieve the hosts from Cluster

$VMHosts = Get-Cluster $Clustername | Get-VMHost | sort Name | % {$_.Name}

# Loop through the hosts

ForEach ($VMHost in $VMHosts) {

    #get all VMs in this host and migrate the network to vSS

    Get-VM -Location $VMHost | Get-NetworkAdapter |

    where { $_.NetworkName -eq $OLDVLANname }

    Set-NetworkAdapter -PortGroup $NEWVLANname -RunAsync;

    }

}

Best regards

Andi

0 Kudos
6 Replies
LucD
Leadership
Leadership

No errors, no messages in the Web Client...?


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

0 Kudos
vmstoani
Contributor
Contributor

Hi Luc,

No Errors, no Messages.

Script OutputPS D:\Scripts\NETWORK> D:\Scripts\NETWORK\MigrateVMfromDVStoVSS - Copy.ps1

Name                           Port  User                         

----                           ----  ----                         

xxxxxxxxxxx            443   xxxxxxxxxx       

 

 

PS D:\Scripts\NETWORK> 

0 Kudos
LucD
Leadership
Leadership

I would suggest to run the script in a debugger (ISE or VSC for example), adn then check if the script actually does what you want it to do.
As an alternative you can put in some Write-Host lines at specific points in the script.


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

0 Kudos
vmstoani
Contributor
Contributor

So it seems that the script stops working on this step:

$VMHost | Get-VM | Get-NetworkAdapter | where { $_.NetworkName -eq $OLDVLANname } | Set-NetworkAdapter -PortGroup $NEWVLANname -RunAsync;

 

But I have no idea why.

 

Best regards

Andi

 

 

 

0 Kudos
LucD
Leadership
Leadership

It might be typo while copying, but there is a pipeline symbol missing at the end of the Where-clause.

$cred = Get-VICredentialStoreItem -File "D:\Scripts\Credentials\credentials.xml"

Connect-VIServer -server $cred.host -User $cred.User -Password $cred.Password

# Read Input File

$InputFile = Import-CSV "D:\Scripts\NETWORK\ARS-OFM.csv" -Delimiter ';'

# Parse the input file

ForEach ($Network in $InputFile) {

   $Clustername = $Network.CLUSTER

   $vSwitchname = $Network.VSS

   $NEWVLANname = $Network.VSSPG

   $OLDVLANname = $Network.VDSPG

   $VLAN = $Network.VLAN

   # Retrieve the hosts from Cluster

   $VMHosts = Get-Cluster $Clustername | Get-VMHost | sort Name

   # Loop through the hosts

   ForEach ($VMHost in $VMHosts) {

   #get all VMs in this host and migrate the network to vSS

   Get-VM -Location $VMHost | Get-NetworkAdapter |

   where { $_.NetworkName -eq $OLDVLANname } |

   Set-NetworkAdapter -PortGroup $NEWVLANname -RunAsync

   }

}


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

0 Kudos
vmstoani
Contributor
Contributor

Hi Luc,

I've changed the script. Now it works.

# Read Input File
$InputFile = Import-CSV "D:\Scripts\NETWORK\ARS-OFM.csv" -Delimiter ';'

# Parse the input file
ForEach ($Network in $InputFile) {
    $Clustername = $Network.CLUSTER
    $vSwitchname = $Network.VSS
    $NewPortGroup = $Network.VSSPG
    $OldPortGroup = $Network.VDSPG
      

# Retrieve Cluster
Get-Cluster $Clustername | Get-VM |Get-NetworkAdapter | Where {$_.NetworkName -eq $OldPortGroup } | Set-NetworkAdapter -NetworkName $NewPortGroup -Confirm:$false
}

Thank's for your assistance

Best regards

Andi


0 Kudos