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.

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

cmdlet Connect-VIServer at command pipeline position 1
Supply values for the following parameters:
Specify Credential
Please specify server credential
User: roger
Password for user roger:*********
Name Port User
—- —- —- 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
$newhost = get-vmhost -name


$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: Logo

You are commenting using your 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.

Blog at

Up ↑

%d bloggers like this: