Hello,
I’m looking for a script that can copy all the Vlans (the portgroups) on certain vSwitch (vSwitch1 in most cases)
Then add them identically to a newly installed ESX (group of ESXs if possible) to the same vSwitch
Thanks in advance.
A simple portgroup replication script.
Note that this does not copy the teaming policy !
If that is needed the script would need to use the Get-NicTeamingPolicy and Set-NicTeamingPolicy cmdlets.
$modelEsxName = "esx1"
$modelSwitchName = "vSwitch1"
$tgtEsxNames = "esx2","esx3","esx4"
$esx = Get-VMHost -Name $modelEsxName
$sw = Get-VirtualSwitch -Name $modelSwitchName -VMHost $esx
$pg = Get-VirtualPortGroup -VirtualSwitch $sw
foreach($newEsx in (Get-VMHost -Name $tgtEsxNames)){
$newSw = Get-VirtualSwitch -Name vSwitch2 -VMHost $newEsx
$pg | %{
$newPg = New-VirtualPortGroup -Name $_.Name -VLanId $_.VLanId -VirtualSwitch $newSw -Confirm:$false
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Alan Renoufs vProfiles script is the best one I know.
http://www.virtu-al.net/2009/06/29/powercli-vprofiles/
A simple portgroup replication script.
Note that this does not copy the teaming policy !
If that is needed the script would need to use the Get-NicTeamingPolicy and Set-NicTeamingPolicy cmdlets.
$modelEsxName = "esx1"
$modelSwitchName = "vSwitch1"
$tgtEsxNames = "esx2","esx3","esx4"
$esx = Get-VMHost -Name $modelEsxName
$sw = Get-VirtualSwitch -Name $modelSwitchName -VMHost $esx
$pg = Get-VirtualPortGroup -VirtualSwitch $sw
foreach($newEsx in (Get-VMHost -Name $tgtEsxNames)){
$newSw = Get-VirtualSwitch -Name vSwitch2 -VMHost $newEsx
$pg | %{
$newPg = New-VirtualPortGroup -Name $_.Name -VLanId $_.VLanId -VirtualSwitch $newSw -Confirm:$false
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Many thanks, I will try this.
But I’m looking for a bit shorter script that only copies the portgroups since ll the other things are already scripted;
The portgroup copy is done by ESX command; (printing all portgroups into file using awk than copy the file and add them)
Seems that doing it with powerCLI will be way faster.