You could definitely file a bug, but that could take weeks/months to fix in the code. I'd recommend simply using netsh in your PowerShell script/code.
Setting rfc3021 IP address via powershell
Hi,
We are using RFC3021 compatible IP subnets (ie. /31 or /32). Hosts are directly connected to routers via L2 separation layer.
For example subnet: 192.168.1.2/31
GW: 192.168.1.2
HOST: 192.168.1.3
MASK: 255.255.255.254
Windows OS's do not suppport RFC3021 officialy. For example DHCP client dosen't work with the above subnet:
But setting this IP statically with changed subnet/prefix to 255.255.255.255 (/32) works from Windows Server 2008 to Windows Server 2019.
(I call this on-link setup - same as in Linux world).
Setting this example address via netsh - no problem:
Setting this same address via UI - with warning, but no other problems:
Result after hitting "Yes":
But setting this address via PowerShell (with prefix 31):
New-NetIPAddress -AddressFamily IPv4 -IPAddress 192.168.1.3 -PrefixLength 31 -DefaultGateway 192.168.1.2 -InterfaceAlias "Internet"
New-NetIPAddress : The parameter is incorrect.
At line:1 char:1
- New-NetIPAddress -AddressFamily IPv4 -IPAddress 192.168.1.3 -PrefixLe ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidArgument: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [New-NetIPAddress], CimException
- FullyQualifiedErrorId : Windows System Error 87,New-NetIPAddress
or with prefix 32:
New-NetIPAddress -AddressFamily IPv4 -IPAddress 192.168.1.3 -PrefixLength 32 -DefaultGateway 192.168.1.2 -InterfaceAlias "Internet"
New-NetIPAddress : DefaultGateway 192.168.1.2 is not on the same network segment (subnet) that is defined by the IP address 192.168.1.3 and PrefixLength 32.
At line:1 char:1
- New-NetIPAddress -AddressFamily IPv4 -IPAddress 192.168.1.3 -PrefixLe ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidArgument: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [New-NetIPAddress], CimException
- FullyQualifiedErrorId : Windows System Error 87,New-NetIPAddress
Both trigger above errors.
I tried to use "-ErrorAction" to "force" this configuration - but no success.
My question is: could this address be setup via powershell? Or is it not supported? (two other configuration interfaces work OK)
Best regards
Windows for business Windows Server User experience PowerShell
2 answers
Sort by: Most helpful
-
-
Randall Falting 1 Reputation point
2021-04-29T05:35:29.763+00:00 It doesnt seem to matter what the prefix is, it seems that the default gateway is the cause. I still get:
New-NetIPAddress : DefaultGateway 192.168.254.2 is not on the same network segment (subnet) that is defined by the IP address 5.5.5.5 and PrefixLength 24.