Collegare un Host a una rete virtuale (Script)

 

Si applica a: System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager

Per rendere disponibile per le macchine virtuali reti logiche in una rete virtuale esterna, è necessario associare la scheda di rete fisica in un host di una rete logica e configurare le impostazioni di rete virtuale.

Per ulteriori informazioni sulla configurazione delle impostazioni di rete negli host Hyper-V, vedere come configurare le impostazioni di rete in un Host Hyper-V.

Dichiarazione di non responsabilità

Lo script seguente accetta input per il VMHostName, LogNetName, HostAdapterName, e VirtualNetName parametri e associa l'host a una rete logica. Lo script crea quindi una rete virtuale nell'host.

# Description:   This script associates a virtual machine host with a logical 
#                network and then creates a virtual network for the host.

Param (
   [parameter(Mandatory=$true)]
   [String] $VMHostName=$(throw "Please provide the name of a virtual machine host."),

   [parameter(Mandatory=$true)]
   [String] $LogNetName=$(throw "Please provide the name of a logical network."),

   [parameter(Mandatory=$true)]
   [String] $HostAdapterName=$(throw "Please provide the name of the host adapter."),

   [parameter(Mandatory=$true)]
   [String] $VirtualNetName=$(throw "Please provide the virtual network name.")
   )

# Get the virtual machine host.
$VMHost = Get-SCVMHost -ComputerName $VMHostName

# Get the logical network.
$LogNet = Get-SCLogicalNetwork -Name $LogNetName

# Get the network adapter for the host.
$HostAdapter = Get-SCVMHostNetworkAdapter -VMHost $VMHost -Name $HostAdapterName

# Set the logical network on the host.
Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $HostAdapter -AddOrSetLogicalNetwork $LogNet

# Create the virtual network.
New-SCVirtualNetwork -Name $VirtualNetName -Description "External virtual network for $VMHost" -VMHost $VMHost -VMHostNetworkAdapter $HostAdapter