添加虚拟机网卡

#添加网卡,不使用VM Network,使用标准交换机
$VMname = "appc01"
$VirtualNetworkname = "vinternet"
$vm = Get-SCVirtualMachine -Name $VMname
$VirtualNetwork =Get-SCVirtualNetwork |?{$_.name -eq $VirtualNetworkname -and $_.vmhost -eq $vm.Hostname}
#通过网卡数量获取SlotID
$SlotId = (Get-SCVirtualNetworkAdapter -vm $vm).count
#新建网卡,使用静态MAC地址,无法直接设置Vlan ID
New-SCVirtualNetworkAdapter -vm $vm -Synthetic -MACAddressType static -VirtualNetwork $virtualnetwork
#通过SlotID设置Vlan ID
$VirtualNetworkAdapter = Get-SCVirtualNetworkAdapter -vm $vm | ? {$_.SlotID -eq $SlotID}
Set-SCVirtualNetworkAdapter $VirtualNetworkAdapter -VLanEnabled $true -VLanID 101

 结果如下图:

==================================================================================

#添加网卡,使用VM Network
$VMname = "appc01"
$VMnetworkname = "vinternet"
$vm = Get-SCVirtualMachine -Name $VMname
$VMnetwork = Get-SCVMNetwork -Name $VMnetworkname
New-SCVirtualNetworkAdapter -vm $vm -Synthetic -MACAddressType static -VMNetwork $vmnetwork -VLanEnabled $true -VLanID 9

结果如下图:

 

==================================================================================

Get-SCVirtualNetwork:

Gets virtual network objects configured on a VMM host.

Get-SCVMNetwork:

Get a VM network.

Get-SCLogicalNetwork:

Get a logical network object.

posted on 2013-12-23 22:29  momingliu11  阅读(624)  评论(0编辑  收藏  举报