当前位置:网站首页>Restore the default routing settings of the primary network card
Restore the default routing settings of the primary network card
2022-06-23 08:43:00 【shawyang】
As Administrator powershell Execute these commands
$gw=(Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'").DHCPServer
$idx=(Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'" | Where-Object {$_.servicename -eq "netkvm"} ).InterfaceIndex
#$idx=(Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'" | Where-Object {$_.Description -notmatch "NGN"} ).InterfaceIndex
#$idx=(Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'" | Where-Object {$_.Description -match "Tencent"} ).InterfaceIndex
#win32-networkadapter、win32-networkadapterconfiguration Some of the properties of the data structure are the same , but win32-networkadapterconfiguration There is no in the data structure of NetConnectionID,win32-networkadapter Only in the data structure of NetConnectionID
$interfacename=Get-WmiObject Win32_NetworkAdapter -Filter 'NetEnabled=True' | Select -ExpandProperty NetConnectionID
#$interfacename=(((netsh interface show interface)[3] -replace ' ', ';') -replace ';;;', '').split(";")[-1].trim(" ")
#$interfacename=(Get-NetAdapter -InterfaceIndex $idx).Name
route delete 0.0.0.0 mask 0.0.0.0 2>$null
route add 0.0.0.0 mask 0.0.0.0 $gw metric 1 IF $idx 2>$null
route add -p 0.0.0.0 mask 0.0.0.0 $gw metric 1 IF $idx 2>$null
The last two sentences depend on the needs
netsh interface set interface $interfacename disabled
netsh interface set interface $interfacename enabled
Reference resources
https://www.powershellgallery.com/packages/PCHardwareConfiguration/1.0.0/Content/Scripts%5CGet-PCNetworkConfiguration.ps1
https://www.powershellgallery.com/packages/PSWinDocumentation/0.1.0/Content/Private%5CComputers.ps1
https://gist.github.com/milesgratz/0285a6c3e9dd2bcfbbc72b441fcb6410
https://www.bookstack.cn/read/powershell-networking-guide/manuscript-renaming-the-network-adapter.md
https://mac-blog.org.ua/powershell-get-ip-adresses-by-connection-name
https://newbedev.com/command-to-find-network-interface-for-ip
https://docs.microsoft.com/zh-tw/windows/win32/cimwin32prov/win32-networkadapterconfiguration
$networkconfig=gwmi -Query "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'"
or
$networkconfig=Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"
$networkconfig.Caption;
$networkconfig.Description;
$networkconfig.SettingID;
$networkconfig.DatabasePath;
$networkconfig.DHCPEnabled;
$networkconfig.DHCPLeaseExpires;
$networkconfig.DHCPLeaseObtained;
$networkconfig.DHCPServer;
$networkconfig.DNSEnabledForWINSResolution;
$networkconfig.DNSHostName;
$networkconfig.DomainDNSRegistrationEnabled;
$networkconfig.FullDNSRegistrationEnabled;
$networkconfig.Index;
$networkconfig.InterfaceIndex;
$networkconfig.IPConnectionMetric;
$networkconfig.IPEnabled;
$networkconfig.IPFilterSecurityEnabled;
$networkconfig.MACAddress;
$networkconfig.ServiceName;
$networkconfig.TcpipNetbiosOptions;
$networkconfig.WINSEnableLMHostsLookup;
https://docs.microsoft.com/zh-tw/windows/win32/cimwin32prov/win32-networkadapter
$network=Get-WmiObject Win32_NetworkAdapter -Filter 'NetEnabled=True'
or
$network=gwmi -Query "SELECT * FROM Win32_NetworkAdapter WHERE NetEnabled = 'True'"
$network.AdapterType;
$network.AdapterTypeID;
$network.Availability;
$network.Caption;
$network.ConfigManagerErrorCode;
$network.ConfigManagerUserConfig;
$network.CreationClassName;
$network.Description;
$network.DeviceID;
$network.GUID;
$network.Index;
$network.Installed;
$network.InterfaceIndex;
$network.MACAddress;
$network.Manufacturer;
$network.MaxNumberControlled;
$network.Name;
$network.NetConnectionID;
$network.NetConnectionStatus;
$network.NetEnabled;
$network.PhysicalAdapter;
$network.PNPDeviceID;
$network.PowerManagementSupported;
$network.ProductName;
$network.ServiceName;
$network.Speed;
$network.SystemCreationClassName;
$network.SystemName;
$network.TimeOfLastReset;
If there is only one network card , This code can get the local connection name , General Chinese and English version 2008R2-2022 System ( contain Win7-Win11)
(Get-WmiObject Win32_NetworkAdapter -Filter 'NetEnabled=True').NetConnectionID
边栏推荐
- Leetcode topic analysis set matrix zeroes
- (resolved) difference between leftmost prefix and overlay index
- C # advanced learning -- virtual method
- Unique paths II of leetcode topic analysis
- What is a dedicated server line
- Linux MySQL installation
- Use newbeecoder UI implements data paging
- Third party payment in the second half: scuffle to symbiosis
- 6、 Web Architecture Design
- USB peripheral driver - configfs
猜你喜欢

The first day of employment more than ten years ago

Monitor the cache update of Eureka client

Install a WGet for your win10

The rtsp/onvif protocol video platform easynvr startup service reports an error "service not found". How to solve it?

Analysis of JMeter pressure measurement results

测试-- 自动化测试selenium(关于API)

Point cloud library PCL from introduction to mastery Chapter 10

297. Serialize and Deserialize Binary Tree

In June, China database industry analysis report was released! Smart wind, train storage and regeneration

Keng dad's "dedication blessing": red packet technology explosion in Alipay Spring Festival Gala
随机推荐
How to solve the problem that flv video stream cannot be played and TS file generation fails due to packet loss?
Leetcode topic analysis sort colors
List interface three sub implementation classes
986. Interval List Intersections
7-palette-calayer and touch
Open source technology exchange batch stream integrated data synchronization engine Chunjun data restore DDL function module analysis
523. Continuous Subarray Sum
The most commonly used 5-stream ETL mode
2-用线段构成图形、坐标转换
Basic use of check boxes and implementation of select all and invert selection functions
Leetcode topic analysis spiral matrix II
[QNX Hypervisor 2.2用户手册]6.1 使用QNX Hypervisor系统
How to sort a dictionary by value or key?
Android kotlin coroutines KTX extension
驱动架构 & platform平台总线驱动模型
Analysis of JMeter pressure measurement results
PCB电路板特性检查项目都有哪些?
Data assets are king, analyzing the relationship between enterprise digital transformation and data asset management
438. Find All Anagrams in a String
Le rapport d'analyse de l'industrie chinoise des bases de données a été publié en juin. Le vent intelligent se lève, les colonnes se régénèrent