new-netipaddress $variable[0] doesn't work in 2016 when invoked remotely

This topic contains 1 reply, has 1 voice, and was last updated by Profile photo of Rob Rob 3 months ago.

  • Author
    Posts
  • #66994
    Profile photo of Rob
    Rob
    Participant

    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}

  • #66999
    Profile photo of Rob
    Rob
    Participant

    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)

You must be logged in to reply to this topic.