Posted in
Virtual Machine Manager,
Windows Powershell |
No Comment | 2,441 views | 12/12/2013 15:03
You can use this script to assign logical network to your Hyper-V hosts.
For example, in this script, “Test_Logical_Network” is assigned to all servers in Test Host Group.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| $VMHosts = Get-VMHost | Where VMHostGroup -like "All Hosts\Test*"
foreach ($VMNode in $VMHosts)
{
$VMHostName = $VMNode.Name
$Job = New-SCExternalJob -Name "$VMHostName Logical Network"
$JobID = $Job.ID
$VMHost = Get-SCVMHost $VMHostName
$vmHostNetworkAdapter = Get-SCVMHostNetworkAdapter -VMHost $VMHost | Where ConnectionName -eq "VmNetwork_team"
Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -Description "" -AvailableForPlacement $true -UsedForManagement $false -JobGroup $JobID
$logicalNetwork = Get-SCLogicalNetwork -Name "Test_Logical_Network"
Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -JobGroup $JobID -AddOrSetLogicalNetwork $logicalNetwork
Set-SCVMHost -VMHost $VMHost -JobGroup $JobID -RunAsynchronously -NumaSpanningEnabled $true
Set-SCExternalJob -Job $Job -Completed -InfoMessage "Logical network eklendi"
} |
$VMHosts = Get-VMHost | Where VMHostGroup -like "All Hosts\Test*"
foreach ($VMNode in $VMHosts)
{
$VMHostName = $VMNode.Name
$Job = New-SCExternalJob -Name "$VMHostName Logical Network"
$JobID = $Job.ID
$VMHost = Get-SCVMHost $VMHostName
$vmHostNetworkAdapter = Get-SCVMHostNetworkAdapter -VMHost $VMHost | Where ConnectionName -eq "VmNetwork_team"
Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -Description "" -AvailableForPlacement $true -UsedForManagement $false -JobGroup $JobID
$logicalNetwork = Get-SCLogicalNetwork -Name "Test_Logical_Network"
Set-SCVMHostNetworkAdapter -VMHostNetworkAdapter $vmHostNetworkAdapter -JobGroup $JobID -AddOrSetLogicalNetwork $logicalNetwork
Set-SCVMHost -VMHost $VMHost -JobGroup $JobID -RunAsynchronously -NumaSpanningEnabled $true
Set-SCExternalJob -Job $Job -Completed -InfoMessage "Logical network eklendi"
}
That will assign all VLANs in Test_Logical_Network to specific Hyper-V host.