I am writing a Powershell script to document and enforce static IPs on a industrial controls network. Part of the heavy lifting involves the Set-NetIPAddress command, formatted as such:
Set-NetIPAddress -AddressFamily IPv4 ` -CimSession $ServerName ` -InterfaceAlias $NICName ` -IPAddress $IPAddress ` -PrefixLength 24When the script executes, despite being in a try/catch, it barfs an error message into the ISE console instead of my log (which is also annoying but I'll focus on the immediate problem here). Here is the error:
Set-NetIPAddress : SERVERNAME: No matching MSFT_NetIPAddress objects found by CIM query for instances of the ROOT/StandardCimv2/MSFT_NetIPAddress class on the ERHIST2 CIM server: SELECT * FROM MSFT_NetIPAddress WHERE ((IPAddress LIKE '126.96.36.199')) AND ((InterfaceAlias LIKE 'PLC Network')) AND ((AddressFamily = 2)). Verify query parameters and retry.My intended result is to set the IP of "PLC Network" on SERVERNAME to 188.8.131.52. Indeed, this command works if I execute it locally. For some reason the error seems to be telling me that it's querying for a NIC named 'PLC Network' with an IP of '184.108.40.206', which I will note that if this were already the case, there would be nothing for me to have this silly script do!
So firstly, am I doing this incorrectly? If not, how do I go about asking someone to make the Set-NetIPAddress use -IPAddress as an input for setting the IP, rather than part of the query?