9

I'm trying to find a way to configure a permanent static IP on Windows 10 IOT devices with their Nic unplugged. I have a script that needs to be run on the devices before they're in place and part of it is configuring the NICs. When I use the following: New-NetIpAddress -InterfaceIndex 10 -IpAddress 192.168.9.10 -PrefixLength 24 -DefaultGateway 192.168.9.1 -AddressFamily IPv4 I get an error New-NetIpAddress : Inconsistent parameters PolicyStore PersistentStore and Dhcp Enabled I attempted to explictly turn off DHCP with Set-NetIPInterface -InterfaceIndex 10 -Dhcp Disabled before ussing the New-NetIpAddress command but I get the same error.

Any suggestions?

Xelorz
  • 93
  • 1
  • 4
  • 1
    This could be the answer: https://stackoverflow.com/questions/38385742/using-powershell-to-set-a-static-ip-on-a-disconnected-network-card-is-it-possib – Lenniey Oct 02 '18 at 15:08

2 Answers2

9

You need to remove the existing DHCP IP address already assigned to the adapter. You should also set the DNS server for the interface. I provided an example below, but replace the xxx.xxx.xxx.xxx with your DNS Server IP Address.

You'll need to disable DHCP in the registry for this interface in the PersistentStore before you can set the IP address.

Set-ItemProperty -Path “HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces\$((Get-NetAdapter -InterfaceIndex 10).InterfaceGuid)” -Name EnableDHCP -Value 0
Remove-NetIpAddress -InterfaceIndex 10 -AddressFamily IPv4
Remove-NetRoute -InterfaceIndex 10 -AddressFamily IPv4 -Confirm:$false
New-NetIpAddress -InterfaceIndex 10 -IpAddress 192.168.9.10 -PrefixLength 24 -DefaultGateway 192.168.9.1 -AddressFamily IPv4
Set-DnsClientServerAddress -InterfaceIndex 10 -ServerAddresses "xxx.xxx.xxx.xxx"

This website has a good example and explanation of the process: https://www.pdq.com/blog/using-powershell-to-set-static-and-dhcp-ip-addresses-part-1/

This website talks about the same problem you're having and their solution: http://www.darrylvanderpeijl.com/inconsistent-parameters-policystore-persistentstore-and-dhcp-enabled/

Tim Liston
  • 736
  • 3
  • 8
  • My full set of code was nearly exactly the same. I used a remove-netipaddress and remove-netroute previous to the new-netipaddresss. It however fails on an unplugged adapter. – Xelorz Oct 02 '18 at 16:48
  • Your code failed, or this code fails on an unplugged adapter? – Tim Liston Oct 02 '18 at 16:49
  • I copy and pasted the code onto the device using 8.8.8.8 as the dns. Same Error: Inconsistent parameters PolicyStore PersistentStore and Dhcp Enabled – Xelorz Oct 02 '18 at 16:51
  • 1
    @Xelorz I updated the answer with an additional step – Tim Liston Oct 02 '18 at 17:40
  • I googled for hours and never came across anything that suggested that. Thanks. – Xelorz Oct 03 '18 at 14:49
  • 1
    Glad I could help. If it worked for you then maybe accept this as the answer to help someone else in the future. [https://stackoverflow.com/help/someone-answers] – Tim Liston Oct 03 '18 at 18:37
1

I had issues on windows 10 1909 with all code I found, it seemed inconsistent. The below code works for me, choose netsh or powershell exclusive code:

$IP = $builddata.templateIP
$SubnetMaskBits = $builddata.Subnetmaskbits
$SubnetMask = $builddata.Subnetmask
$Gateway = $builddata.gateway
$Dns = $builddata.DNS1,$builddata.DNS2

$IPType = "IPv4"
$adapter = Get-NetAdapter | Where-Object {$_.InterfaceDescription -like "vmx*"} #looking for vmxnet3

# you can use either at this point
# via netsh

netsh interface ipv4 set interface $adapter.InterfaceIndex dadtransmits=0 store=persistent
netsh interface ip set address name="$($adapter.name)" static $IP $SubnetMask $Gateway 1

# via PowerShell

$adapter | Get-NetIPInterface | ? {$_.addressfamily -eq  $IPType} | % {Get-NetIPAddress | Remove-NetIPAddress -Confirm:$false}
$adapter | Get-NetIPInterface | New-NetIPAddress `
     -AddressFamily $IPType `
     -IPAddress $IP `
     -PrefixLength $SubnetMaskBits `
     -DefaultGateway $Gateway -Confirm:$false