From f774984e9df2e653921431a32e3f918d4463ee77 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Wed, 11 Feb 2026 20:41:40 -0600 Subject: [PATCH] Add set-network.ps1 --- set-network.ps1 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 set-network.ps1 diff --git a/set-network.ps1 b/set-network.ps1 new file mode 100644 index 0000000..0f7dc24 --- /dev/null +++ b/set-network.ps1 @@ -0,0 +1,46 @@ +$ActiveIndex = (Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Sort-Object RouteMetric | Select-Object -First 1).InterfaceIndex +$adapter = Get-NetAdapter -InterfaceIndex $ActiveIndex | Select-Object Name, Status, InterfaceGuid, @{Name="DefaultGateway"; Expression={(Get-NetRoute -InterfaceIndex $ActiveIndex -DestinationPrefix "0.0.0.0/0").NextHop}} + +$adapter + +$guid = $adapter.InterfaceGuid + +Write-Host "`nDeleting registry config for $($adapter.Name)..." -ForegroundColor Yellow +Remove-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\$guid" -Recurse -Force + +Write-Host "`nConfigure new network settings for $($adapter.Name):" -ForegroundColor Cyan + +$adapters = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled = True" | Select-Object -first 1 + +$ipaddress = $($adapters.IPAddress)[0] +$subnet = (Get-NetIPAddress -InterfaceIndex $ActiveIndex -AddressFamily IPv4).PrefixLength +$gateway = $($adapters.DefaultIPGateway) +$dns = @($adapters.DNSServerSearchOrder) +$dns1 = $dns[0] +$dns2 = $dns[1] + +Write-Host "`n-Output of ipv4 info- +ipaddress: $ipaddress +subnet: $subnet +gateway: $gateway +primary dns: $dns1 +secondary dns: $dns2" -ForegroundColor Cyan + + +Remove-NetIPAddress -InterfaceIndex $ActiveIndex -Confirm:$false -ErrorAction SilentlyContinue +Remove-NetRoute -InterfaceIndex $ActiveIndex -Confirm:$false -ErrorAction SilentlyContinue + +$ActiveIndex = (Get-NetRoute -DestinationPrefix "0.0.0.0/0" | Sort-Object RouteMetric | Select-Object -First 1).InterfaceIndex +$adapter = Get-NetAdapter -InterfaceIndex $ActiveIndex | Select-Object Name, Status, InterfaceGuid, @{Name="DefaultGateway"; Expression={(Get-NetRoute -InterfaceIndex $ActiveIndex -DestinationPrefix "0.0.0.0/0").NextHop}} + +New-NetIPAddress -InterfaceIndex $ActiveIndex -IPAddress $ipaddress -PrefixLength $subnet -DefaultGateway $gateway +Set-DnsClientServerAddress -InterfaceIndex $ActiveIndex -ServerAddresses @($dns1, $dns2) + +Write-Host "`nNew configuration applied:" -ForegroundColor Green +Get-NetIPConfiguration -InterfaceIndex $ActiveIndex + +Write-Host "`nDownloading VMware removal and running:" -ForegroundColor Green +Invoke-Expression "& { $(Invoke-RestMethod https://gist.githubusercontent.com/Jason-Clark-FG/68e23b534f5be4e3f3b43f3bd37f1d65/raw/3cb722298d72d2d12f2e7359473308925c4b8081/Uninstall-VMwareTools.ps1) } -Uninstall -Force" + +Write-Host "`nVM ip reconfig and driver cleanup complete" -ForegroundColor Green + \ No newline at end of file