This page looks best with JavaScript enabled

[PowerCLI] Generate an HTML report on VM virtual disk

 ·  β˜• 1 min read  ·  πŸ¦† Jeremy

Script

It’s all in the title, a simple but effective script 😊

Choose a source ESXi (the one on which the vSwitch whose PortGroup you want to copy the PortGroup is located) and a destination ESXi. Same for the source and destination vSwitch.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
## ESXi source and destination
$esx_s = Get-VMHost esx01*
$esx_d = Get-VMHost esx02*

## vSwitch name source and destination
$vswitch_s = "vSwitch1"
$vswitch_d = "vSwitch1"

$portgroup = $esx_s | Get-VirtualSwitch -Name $vswitch_s | Get-VirtualPortGroup | Select-Object Name, vlanid

$vswitch = $esx_d | Get-VirtualSwitch -Name $vswitch_d 

### Add Port Group

FOREACH ($pg in $portgroup) {
    Write-Host "Creating ProtGroup {0} with vlanid {1}" -f $pg.name, $pg.vlanid
    TRY{
        New-VirtualPortGroup -VirtualSwitch $vswitch -Name $pg.name -VlanId $pg.vlanid -ErrorAction Stop
    }
    CATCH{"Port group already exist"}
}
Share on