Copy vswitch vlan from one host to another with powershell. @VMware #vExpert #esxi #VMware

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.