new1234.jpg

Archive

Posts Tagged ‘Network Label’

VMware: Mass change portgroup VM’s in cluster with PowerCLI

January 10th, 2013 3 comments

Last week I configured for a customer some new VLAN’s and created on each host new vSwitches with new portgroups, to migrate all VM’s in cluster with network label “VM Network” to “Production” I’ve created this script to automate this for all virtual machines with specific network label in cluster:

Original situation:

image


Script
:

#====================================================================#
#   SCRIPT:        PowerCLI_Mass_change_network_label.ps1            #
#   FUNCTION:      Mass change network label Network A to Network B  #
#   OWNER:         Sander Daems                                      #
#   VSPHERE:       5.0 Update 1 build 623860                         #
#   CREATED:       10/01/2013                                        #
#   MODIFIED:      10/01/2013                                        #
#   VERSION:       v.1.0                                             #
#====================================================================#
#   CHANGELOG:                                                       #
#                                                                    #
#    v.1.0                                                           #
#    - Script created;                                               #
#                                                                    #
#====================================================================#
#   HOST - Specify host and connect                                  #
#====================================================================#
$vCenterServer = Read-Host "Enter vCenter Hostname / IP"
Connect-VIServer $vCenterServer
#
#====================================================================#
# CUSTOM DEFINITIONS                                                 #
#====================================================================#
$Cluster = "Cluster01" 
$SourcePortgroup = "VM Network" 
$DestinationPortgroup = "Production" 
#
#====================================================================#
# SCRIPT                                                             #
#====================================================================#
Get-Cluster $Cluster | Get-VM | Get-NetworkAdapter | Where {$_.NetworkName -eq $SourcePortgroup } | Set-NetworkAdapter -NetworkName $DestinationPortgroup -Confirm:$false#====================================================================#

 

Result:


New situation
 (All VM’s in cluster):

image

sanderdaems

Sander Daems is founder and author of this blog and working as a Lead (Sr.) Consultant by UNICA ICT Solutions. Sander has over 15 years experience in IT, primary focus: virtualization and modern worksplace.

More Posts - Website

Follow Me:
TwitterLinkedIn