Compartilhar via


Conectar um Host a uma rede Virtual (Script)

 

Aplica-se a: System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager

Para disponibilizar redes lógicas para máquinas virtuais em uma rede virtual externa, você deve associar uma rede lógica com o adaptador de rede física em um host e definir configurações de rede virtual.

Para obter mais informações sobre como definir configurações de rede nos hosts Hyper-V, consulte como definir as configurações de rede em um Host Hyper-V.

Isenção de responsabilidade

O script a seguir usa a entrada para o VMHostName, LogNetName, HostAdapterName, e VirtualNetName parâmetros e associa o host uma rede lógica. O script cria uma rede virtual no 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