Add set-network.ps1
This commit is contained in:
46
set-network.ps1
Normal file
46
set-network.ps1
Normal file
@@ -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
|
||||||
|
|
||||||
Reference in New Issue
Block a user