diff options
| author | Dave Wilson <[email protected]> | 2015-03-17 19:50:07 -0700 |
|---|---|---|
| committer | Dave Wilson <[email protected]> | 2015-03-17 19:50:07 -0700 |
| commit | 97cf5197cf5b882b2c689d8dc2b555f2edf8f418 (patch) | |
| tree | 46f3701832d70b420eb0fc0eb93261f9da45db3f /network/ndis/extension/samples/forward/setRoute.ps1 | |
| parent | ef1905bf1e8825bb31120dfb27e0daf3154d859a (diff) | |
Initial publish
Diffstat (limited to 'network/ndis/extension/samples/forward/setRoute.ps1')
| -rw-r--r-- | network/ndis/extension/samples/forward/setRoute.ps1 | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/network/ndis/extension/samples/forward/setRoute.ps1 b/network/ndis/extension/samples/forward/setRoute.ps1 new file mode 100644 index 00000000..71899087 --- /dev/null +++ b/network/ndis/extension/samples/forward/setRoute.ps1 @@ -0,0 +1,54 @@ +# +# Copyright (c) Microsoft Corporation. All Rights Reserved. +# + +function StringToMacAddress([String]$MacString) +{ + $zeroVal = [int]("0"[0]); + $aVal = [int]("A"[0]); + + $macArray = @(); + $byteOne = 0; + $byteTwo = 0; + + for($i = 0; $i -lt 6; $i++) + { + $byteChars = $MacString.ToCharArray(2*$i, 2); + + $byteOne = $byteChars[0] - $zeroVal; + $byteTwo = $byteChars[1] - $zeroVal; + + if($byteOne -gt 9) + { + $byteOne = $byteChars[0] - $aVal + 10; + } + if($byteTwo -gt 9) + { + $byteTwo = $byteChars[1] - $aVal + 10; + } + + $byteVal = 16*($byteOne) + ($byteTwo); + $macArray = $macArray + $byteVal; + } + + return $macArray +} + +Import-Module Hyper-V + +$vmArr = Get-VM +$switch = Get-VmSwitch -Name "CorpNet" +$policy = Get-VmSystemSwitchExtensionSwitchFeature -FeatureName "MSForwardExt Mac Address Policy" + +foreach($vm in $vmArr) +{ + $vmName = $vm.Name + $adapters = Get-VmNetworkAdapter -VmName $vmName + + foreach($adapter in $adapters) + { + Write-Host "Setting Policy for $vmName..." + $policy.SettingData.MacAddress = StringToMacAddress($adapter.MacAddress) + Add-VmSwitchExtensionSwitchFeature -VmSwitch $switch -VMSwitchExtensionFeature $policy + } +} |
