Set Port Classification based on VM Network

When you share one Logical network for two purposes like Management and Backup you might want to setup Port Classifications and Port Profiles.
With the Port Classifications and Port Profiles you can setup QOS so the backup traffic will never influence the management traffic.

One thing not to forget is to select the Port Profile, if you don’t select a port profile it will use the default port profile.
In this case it would use the Management Port Profile (with no max. bandwith) for backup traffic and that would not be a good idea, so I want to make sure the right Port Profile is selected.

portclass1

The following powershell script checks every Virtual Network Adapter in the specified VM Network.
If the Virtual Network Adapter in the specified VM Network does not have the right Port Classification, it will set it right.

$VMNetwork = Get-SCVMNetwork -VMMServer vmm.domain.local -Name "Backup"
$PortClassification = Get-SCPortClassification -VMMServer vmm.domain.local | where {$_.Name -eq "Backup Port Classification"}

Get-SCVirtualNetworkAdapter -VMMServer vmm.hypergrid.local -all | where {$_.VMNetwork -eq $VMNetwork -and $_.PortClassification -ne $PortClassification} | foreach {
$VM = Get-SCVirtualMachine -Name $_.NAME
$ID = $_.ID
$VirtualNetworkAdapter = Get-SCVirtualNetworkAdapter -VM $VM | where {$_.ID -eq $ID}

Set-SCVirtualNetworkAdapter $VirtualNetworkAdapter -PortClassification $PortClassification
}

I’m running this script every day 10:00 PM (before backup window starts) to make sure all the VM’s and Port Classifications are set right in case someone forgot.

Leave a Reply

Your email address will not be published. Required fields are marked *