Author Posts

March 22, 2017 at 7:05 pm

Hello, having a weird issue. I wrote some code that will assign a random 192.168.0.x IP to a 10gb adapter on a remote machine. It works fine when run on 2k12r2 machines, but fails on 2k16 machines. I seem to have narrowed it down to the fact that my code grabs a list of the 10gb adapters on the machine, puts them into a variable, and then I select the first nic it grabbed by using $variable[0]. This works on 2k12r2 but no 2016. For some reason, having the [0] on the end of the variable in 2016 causes:
The system cannot find the file specified.
+ CategoryInfo : ObjectNotFound: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [New-NetIPAddress], CimException
+ FullyQualifiedErrorId : Windows System Error 2,New-NetIPAddress
+ PSComputerName : e-rack-14

Note the same command I am invoking can be run locally on the 2016 machine with the $variable[0]. For some reason invoking it causes it to fail. Anyone know what is going on?

invoke-command -ComputerName $n -Credential $Win_Credentials -ScriptBlock {$nic=(Get-NetAdapter -Physical | Where-Object linkspeed -EQ '10 gbps').InterfaceAlias; $octet = get-random -Minimum 2 -Maximum 253;
New-NetIPAddress -ipaddress 192.168.0.$octet -InterfaceAlias $nic[0] -PrefixLength 24 -AddressFamily IPv4}

March 22, 2017 at 8:45 pm

Well I just realized I was just thinking about this too hard. There is no reason for me to find the 192.x.x.x IP, then specify it to be removed. I realized that just remotely setting the adapter to DHCP accomplishes the same goal of removing the IP (Doesn't need to be specific in my case)