连接到虚拟网络 (脚本)

 

适用对象:System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager

若要使逻辑网络上的外部虚拟网络可供虚拟机,您必须将逻辑网络与主机上的物理网络适配器相关联并配置虚拟网络设置。

有关在 HYPER-V 主机上配置网络设置的详细信息,请参阅 如何在 HYPER-V 主机上配置网络设置

免责声明

下面的脚本将为输入 VMHostName, ,LogNetName, ,HostAdapterName, ,和 VirtualNetName 参数并将主机与逻辑网络相关联。 然后,脚本创建虚拟网络在主机上。

# 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