Score:0

How to add persistent IP address in powershell

us flag

Why can I successfully add an IP address with this command

New-NetIPAddress -IPAddress 192.168.0.168 -PrefixLength 24 -InterfaceIndex 34

but the same command fails for persistent address

New-NetIPAddress -IPAddress 192.168.0.168 -PrefixLength 24 -InterfaceIndex 34 -PolicyStore PersistentStore

New-NetIPAddress : Invalid parameter PolicyStore PersistentStore
At line:1 char:1
+ New-NetIPAddress -IPAddress 192.168.0.168 -PrefixLength 24 -Interface ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [New-NetIPAddress], CimException
    + FullyQualifiedErrorId : Windows System Error 87,New-NetIPAddress

Running in PowerShell 5.1 as Administrator.

cn flag
It is complaining that the parameter `PolicyStore PersistentStore` is invalid for the WMI object 'MSFT_NetIPAddress' 'Store' property during creation. Is there a reason you are specifying this? According to the documentation "*If you do not specify this parameter, the default entries are created in both the ActiveStore and the PersistentStore.*" Also note that the default behavior of the MSFT_NetIPAddress class is to create persistent objects, and the documentation is "TBD" - not a good sign. https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh872425(v=vs.85)
us flag
Well, Greg, if it's already persistent then I suggest you to post it as an answer so that I can mark it as correct one. It's really strange New-NetIPAddress command does not accept the argument listed in its documentation.
cn flag
You may want to specify if the command that does not produce an error does not produce the desired results. It isn't clear from the question and comments. Also, there is a *lot* of WMI network stuff that either is not implemented, or just doesn't work. Part of knowing the Windows ecosystem landscape.
Score:0
us flag

As Greg Askew explained in the comments, PolicyStore is irrelevant for New-NetIPAddress command even though it's an officially documented command argument.

This command

New-NetIPAddress -IPAddress 192.168.0.168 -PrefixLength 24 -InterfaceIndex 34

creates persistent IP address anyways.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.