问题原文
原帖链接 · Xelorz · CC BY-SA 4.0
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?
已采纳解答
原帖链接 · Tim Liston · CC BY-SA 4.0
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/
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
