Skip to content

Commit 200bead

Browse files
Fix issue of 801
Based on clong#801 (comment) so credit goes to him
1 parent f9c12f9 commit 200bead

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# explanation of script>
2+
# 1. get list of all IP's on VM
3+
# 2. find interface with ip in correct subnet. I.e. same range as DNS=192.168.56.102
4+
# 3. Change the interfaceMetric of this interface to have higher priority than the others
5+
6+
# Step 1
7+
$ips=Get-NetIPAddress
8+
9+
# Step 2
10+
# Two variables used in while-loop.
11+
$correctInterfaceIndex=''
12+
[bool]$correctInterface # Cast variable to boolean. Used in while loop
13+
$i=0
14+
15+
# While loop> run until correct interface is found
16+
while ($i -le $ips.Length -and !$correctInterfaceIndex ) {
17+
#$ips[$i].IPAddress
18+
if ($ips[$i].IPAddress -like "*192.168.*"){
19+
$correctInterfaceIndex=$ips[$i].InterfaceIndex
20+
#$correctInterfaceIndex
21+
}
22+
$i++
23+
}
24+
25+
#Step 3
26+
#Get current InterfaceMetric of NetworkInterface with index $correntInterfaceIndex
27+
$current_interface_metric=$(Get-NetIPInterface -InterfaceIndex $correctInterfaceIndex).InterfaceMetric
28+
$current_interface_metric
29+
30+
# Set interfaceMetric with higher priority
31+
Set-NetIPInterface -InterfaceIndex $correctInterfaceIndex -InterfaceMetric $($current_interface_metric-1)
32+
$(Get-NetIPInterface -InterfaceIndex $correctInterfaceIndex).InterfaceMetric

Vagrant/scripts/join-domain.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ If (($hostname -eq "wef") -or ($hostname -eq "exchange")) {
4444
While ($tries -lt 3) {
4545
Try {
4646
$tries += 1
47+
. c:\vagrant\scripts\fix-failed-to-join-domain_interface-issue.ps1
4748
Write-Host "$('[{0:HH:mm}]' -f (Get-Date)) Try # $tries"
4849
Add-Computer -DomainName "windomain.local" -credential $DomainCred -OUPath "ou=Workstations,dc=windomain,dc=local"
4950
Break

0 commit comments

Comments
 (0)