VMware Cloud Community
Pete_Howarth
Enthusiast
Enthusiast
Jump to solution

Script to Repoint a list of VM's NICS to a different DVS and port group.

I'm looking for a script that will take a list of existing VM's up to 1000 and repoint their existing NICS to a different DVS and port group.  

Thanks,

Pete

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something along these lines

Import-Csv -Path .\vms.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
    $pg = Get-VDSwitch -Name $row.TargetVDS | Get-VDPortgroup -Name $row.TargetPortgroup
    Get-VM -Name $row.Name | Get-NetworkAdapter |
    Set-NetworkAdapter -Portgroup $pg -Confirm:$false
}


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

This is basically doing, in a loop, a Get-NetworkAdapter and Set-NetworkAdapter , with the Portgroup parameter, for each vNIC of all the VMs.
You didn't say how you get these VMs.
Is that from a CSV file or through a Get-VM from a specific location?


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

0 Kudos
Pete_Howarth
Enthusiast
Enthusiast
Jump to solution

Yeah.  I'm just going to export a list of the VMs.  Possibly from RVTOOLS with their port group.  Then possibly have three columns in the csv.  Name, Target DSV, Target PortGroup.  Then then let it reconfigure the VM's.

Tags (1)
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something along these lines

Import-Csv -Path .\vms.csv -UseCulture -PipelineVariable row |
ForEach-Object -Process {
    $pg = Get-VDSwitch -Name $row.TargetVDS | Get-VDPortgroup -Name $row.TargetPortgroup
    Get-VM -Name $row.Name | Get-NetworkAdapter |
    Set-NetworkAdapter -Portgroup $pg -Confirm:$false
}


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

0 Kudos