PowerCLI

 View Only
  • 1.  [vsphere 7] Create new TCP/IP vmotion stack

    Posted Mar 09, 2021 09:56 AM

    In 6.7, i use a script to install ESX hosts. A part of that script is not working anymore when testing this to an ESX server running on 7. Its the part where setup the vmotion vmk to use a newly create vmotion tcp/ip stack.

     

    import-csv $dir\hosts.txt -Header vmhost,ip1,ip2 | foreach {
    
    $line = $_
    $line.vmhost
    $vmhost = get-vmhost $_.vmhost
    $esxcli = get-esxcli -vmhost $vmhost.name -v2
    
    
    New-VMHostNetworkAdapter -VMHost $_.vmhost -PortGroup $vmotion1 -VirtualSwitch $vdswitch -IP $_.ip1 -SubnetMask 255.255.255.0 -VMotionEnabled $true #vmotion
    sleep 5
    New-VMHostNetworkAdapter -VMHost $_.vmhost -PortGroup $vmotion2 -VirtualSwitch $vdswitch -IP $_.ip2 -SubnetMask 255.255.255.0 -VMotionEnabled $true #vmotion
    sleep 5
    
    $line = $_
    $line.vmhost
    $vmhost = get-vmhost $_.vmhost
    $esxcli = get-esxcli -vmhost $vmhost.name -v2
    
    write-host -foregroundcolor green "create vmotion stack"
    $esxcli.network.ip.netstack.add.Invoke(@{netstack = 'vmotion'})
    sleep 10
    
    write-host -foregroundcolor green "create vmk1, vmotion1"
    $vmk1 = New-VMHostNetworkAdapter -VMHost $line.vmhost -PortGroup $vmotion1 -virtualSwitch $vdswitch
    sleep 10
    $np1 = ( get-vdswitch -vmhost $vmhost | get-vdportgroup $vmotion1 | get-vdPort | ? {$_.ProxyHost -match $vmhost.name})
    sleep 10
    $arguments = $esxcli.network.ip.interface.remove.CreateArgs()
    $arguments.dvportid = $np1.Id
    $arguments.dvsname = $np1.Switch
    $esxcli.network.ip.interface.remove.Invoke($arguments)
    
    sleep 10
    $arguments = $esxcli.network.ip.interface.add.CreateArgs()
    $arguments.mtu = 9000
    $arguments.dvsname = $np1.Switch
    $arguments.netstack = "vmotion"
    $arguments.interfacename = $np1.ConnectedEntity
    $arguments.dvportid = $np1.Id
    $esxcli.network.ip.interface.add.Invoke($arguments)
    sleep 10
    $vmhost | get-vmhostnetworkadapter -name vmk1 | set-vmhostnetworkadapter -ip $_.ip1 -subnet $vmotionsubnet -mtu 9000 -confirm:$false
    sleep 10
    
    write-host -foregroundcolor green "create vmk2, vmotion2"
    $vmk2 = New-VMHostNetworkAdapter -VMHost $line.vmhost -PortGroup $vmotion2 -virtualSwitch $vdswitch
    sleep 10
    $np2 = ( get-vdswitch -vmhost $vmhost | get-vdportgroup $vmotion2 | get-vdPort | ? {$_.ProxyHost -match $vmhost.name})
    sleep 10
    $arguments = $esxcli.network.ip.interface.remove.CreateArgs()
    $arguments.dvportid = $np2.Id
    $arguments.dvsname = $np2.Switch
    $esxcli.network.ip.interface.remove.Invoke($arguments)
    
    sleep 10
    $arguments = $esxcli.network.ip.interface.add.CreateArgs()
    $arguments.mtu = 9000
    $arguments.dvsname = $np2.Switch
    $arguments.netstack = "vmotion"
    $arguments.interfacename = $np2.ConnectedEntity
    $arguments.dvportid = $np2.Id
    $esxcli.network.ip.interface.add.Invoke($arguments)
    
    sleep 10
    $vmhost | get-vmhostnetworkadapter -name vmk2 | set-vmhostnetworkadapter -ip $_.ip2 -subnet $vmotionsubnet -mtu 9000 -confirm:$false
    }

     

     

    The creation of the vmotion stack works, but removing of the tmp vmk doenst work. In stead, there are four VMK's created

     

    create vmk1, vmotion1
    A specified parameter was not correct: argument[0]
    At ~removed.ps1:110 char:1
    + $esxcli.network.ip.interface.remove.Invoke($arguments)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (:) [], InvalidArgument
    + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidArgument

    A specified parameter was not correct: argument[0]
    At~removed.ps1:119 char:1
    + $esxcli.network.ip.interface.add.Invoke($arguments)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (:) [], InvalidArgument
    + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidArgument

     

    Runnning on PowerCLI 12.0.0 build 15947286

     

    Anyone got an idea got point me in the right direction?



  • 2.  RE: [vsphere 7] Create new TCP/IP vmotion stack

    Posted Mar 09, 2021 10:44 AM

    Try using New-VMHostNetworkAdapter -NetworkStack vmotion ...



  • 3.  RE: [vsphere 7] Create new TCP/IP vmotion stack

    Posted Mar 09, 2021 12:06 PM

     

    Ah nice, i will try and see if it works. Will come back to this! Thanks

     

    Indeed not sure, can double check that.

    and about $vmotion1, that has been initialised earlier in the code. This is just a snip of the entire code



  • 4.  RE: [vsphere 7] Create new TCP/IP vmotion stack

    Posted Mar 09, 2021 12:14 PM
    New-VMHostNetworkAdapter -VMHost $_.vmhost -PortGroup $vmotion1 -VirtualSwitch $vdswitch -IP $_.ip1 -SubnetMask 255.255.255.0 -NetworkStack vmotion  -VMotionEnabled $true 

     

    Gives me:

     

    New-VMHostNetworkAdapter : Cannot bind parameter 'NetworkStack'. Cannot convert the "vmotion" value of type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.Host.Networking.HostNetworkSt
    ack".



  • 5.  RE: [vsphere 7] Create new TCP/IP vmotion stack

    Posted Mar 09, 2021 12:20 PM

    You need the object returned by Get-VMHostNetworkStack, not the string



  • 6.  RE: [vsphere 7] Create new TCP/IP vmotion stack

    Posted Mar 09, 2021 11:31 AM

    Are you sure that $np1 only contains 1 port?
    Btw, the $vmotion1 variable doesn't seem to be initialised in your code