Last active
September 18, 2024 16:46
-
-
Save stoyanovgeorge/6c980a7f698c7816f704a49a9e5270e8 to your computer and use it in GitHub Desktop.
A batch script for Windows 10 which can change the IP address, the network mask, the gateway, the DNS and the VLAN ID of an interface. You need to execute the script with admin rights.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Configuration Variables | |
set "ifName=Ethernet 2" | |
set "ipAddress=10.88.167.35" | |
set "subnetMask=255.255.255.240" | |
set "vlanID=702" | |
:: set "defaultGateway=x.x.x.x" | |
:: set "primaryDNS=x.x.x.x" | |
:: set "alternateDNS=x.x.x.x" | |
:: Change of IP address and NetMask :: | |
netsh interface ipv4 set address name="%ifName%" source=static addr=%ipAddress% mask=%subnetMask% | |
:: netsh interface ipv4 set dns "%ifName%" static %primaryDNS% | |
:: netsh interface ipv4 add dns "%ifName%" %alternateDNS% index=2 | |
:: Disable :: | |
:: netsh interface set interface "%ifName%" DISABLED | |
:: Change VLAN ID :: | |
powershell -Command "& {Set-NetAdapter -Name '%ifName%' -VlanID %vlanID% -Confirm:$false}" | |
echo The VLAN ID of %ifName% has been successfully changed to %vlanID% | |
:: Enable :: | |
:: netsh interface set interface "%ifName%" ENABLED | |
powershell -Command "Start-Sleep -s 5" | |
:: pause > nul |
allo powershell not found on the all lwindows system dot not use powershell command please
use online command available work windows 7/8/10/11
powerhsell not found on windows 7 dot not use
replace powershell code by batch or vbs please
In the description of the gist, it is clearly stated that this is tested on Windows 10. Powershell is also available on Windows 7 but the specific cmdlets for managing network adapters are not there by default. In addition, Windows 7 support ended on 14.01.2020.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
allo powershell not found on the all lwindows system dot not use powershell command please
use online command available work windows 7/8/10/11
powerhsell not found on windows 7 dot not use
replace powershell code by batch or vbs please