Search code examples
wmipowershell-cmdlet

How to assign Static IP based on MAC Address using powershell/script in Windows?


I would like to write up a script to assign static IP based on mac addresses, as I am having trouble with "USB to ethernet" adapters lose it's IP settings and assign to different interface Names.

I am running on windows 10 environment and have found a wmi script online that I think might work.

Code I am using:

wmic nicconfig where macaddress="0F:98:90:D6:42:92" call EnableStatic ("192.168.1.1"), ("255.255.255.0")

Error output: "Invalid format. Hint: = [, ]."

Thanks


Solution

  • Something like this

    $netAdapter = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.MACAddress -eq '0F:98:90:D6:42:92'}

    $netAdapter.EnableStatic("192.168.1.1", "255.255.255.0")