2 Replies Latest reply on Jul 27, 2012 3:10 AM by StephVP

    Deploying a VM with Multiple NICs in PowerCLI.


      I need to deploy VMs with a PowerCLI script. I'm running the  following command line in a loop to configure Multiple NICS and IP addresses on the deployed VM:   "Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $ipaddr  -SubnetMask $subnet -DefaultGateway $gateway -Dns $dns1,$dns2"

      but I do not  want to set a Default Gateway on each Netword card even if the -IPMode is  UseStaticIp.

      As a current Workaround I run a netsh  command to delete the Gateway after starting the VM.


      Does  anyone has a solution to Deploy a VM with multiple NICs with Static IP  addresses without configuring Default Gateway in PowerCLI?


      Thanks for your Help,

        • 1. Re: Deploying a VM with Multiple NICs in PowerCLI.
          LucD Guru
          User ModeratorsvExpertCommunity Warriors

          It looks as if the requirement to include a default gateway is not justified in vSphere 5.*.

          If you use the CreateCustomizationSpec method, you can easily skip entering the default gateway (and the subnetmask as well for that matter).


          This sample code produces a CustomizationSpec with 3 NICs included and without a default gateway.


          $specMgr = Get-View CustomizationSpecManager
          = New-Object VMware.Vim.CustomizationSpecItem
          .Info = New-Object VMware.Vim.CustomizationSpecInfo
          $item.Info.Name = "TestMultNICSDK"
          $item.Info.Description = "Testing with the SDK method"
          $item.Info.Type = "Windows"
          .Spec = New-Object VMware.Vim.CustomizationSpec

          .Spec.globalIPSettings = New-Object VMware.Vim.CustomizationGlobalIPSettings
          .Spec.identity = New-Object VMware.Vim.CustomizationSysprep

          .Spec.identity.guiUnattended = New-Object VMware.Vim.CustomizationGuiUnattended
          .Spec.identity.guiUnattended.autoLogon = $false
          .Spec.identity.guiUnattended.autoLogonCount = 0
          $item.Spec.identity.guiUnattended.timeZone = 0
          .Spec.identity.identification = New-Object VMware.Vim.CustomizationIdentification
          $item.Spec.identity.identification.JoinWorkgroup = "MYWG"
          .Spec.identity.UserData = New-Object VMware.Vim.CustomizationUserData
          $item.Spec.identity.UserData.FullName = "My Fullname"
          $item.Spec.identity.UserData.OrgName = "My Orgname"
          $item.Spec.identity.UserData.ProductId = ""
          $item.Spec.identity.UserData.ComputerName = New-Object VMware.Vim.CustomizationVirtualMachineName
          .Spec.Options = New-Object VMware.Vim.CustomizationWinOptions
          .Spec.Options.ChangeSID = $false
          $item.Spec.Options.DeleteAccounts = $false
          ..3 | %{   $nic = New-Object VMware.Vim.CustomizationAdapterMapping
            $nic.Adapter = New-Object VMware.Vim.CustomizationIPSettings
            $nic.Adapter.ip = New-Object VMware.Vim.CustomizationFixedIp
            $nic.Adapter.ip.ipAddress = "192.168.1.$_"
          $nic.Adapter.subnetMask = ""
            $item.Spec.nicSettingMap += $nic
          • 2. Re: Deploying a VM with Multiple NICs in PowerCLI.
            StephVP Lurker

            Many thanks, it works.

            I just added a $nic.Adapter.Gateway = $gateway instruction to set a default gateway on NIC #1.