This simple powershell scripts copy vlans from one server to another. With this script I needed to manually create the vmotion network after. But all other vlans was ccreated.
Start Powershell In this case I was running linux.
pwsh
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
Connect-VIServer
cmdlet Connect-VIServer at command pipeline position 1
Supply values for the following parameters:
Server[0]: vcenter.server.se
Specify Credential
Please specify server credential
User: roger
Password for user roger:*********
Name Port User
—- —- —-
vcenter.server.se 443 domain\roger
Start the script
First we define the old and new host. Old is where you want as source. New is defined as destination. In this case we want copyt vswitch0 to vswitch0
$oldhost = get-vmhost -name esx1.server.se $newhost = get-vmhost -name esx2.server.se
$oldhost | get-virtualswitch -name vSwitch0 | get-virtualportgroup | foreach { $newportgroup = $newhost | get-virtualswitch -name vSwitch0 | new-virtualportgroup -name $_.Name -VLanID $_.VLanID }
New-VirtualPortGroup: 5/11/2020 3:54:39 PM New-VirtualPortGroup The specified key, name, or identifier ‘pgName’ already exists.
PS /home/roger>
Leave a Reply