locked
NetworkAdapter not setting? RRS feed

  • Question

  • Hi All

    I've created the below script - everything works as expected bar the last line. No failure appears it just simply doesn't seem to recognise the command.

    When i run this command manually or in a script on its own it recognises it without issue.

    Any ideas?

    Thank you


    $vCenter = "xxxxxx.xxx.xxxxx.com"
    $vCenterUser = "Testing.Account"
    $vCenterPassword =  "XXXXXXX"

    Connect-VIServer -server $vCenter -user $vCenterUser -password $vCenterPassword

    $vms = Import-Csv "C:\Scripts\VMRollOut.csv"

    #set VM variables
    foreach ($vm in $vms){
    $VMName = $vm.Name
    $Cluster = $vm.Cluster
    $ESXHost = Get-VMHost $vm.ESXHost 
    $ESXDatastore = Get-Datastore $vm.Datastore
    $NoCPU = $vm.NoCPU
    $MBRAM = $vm.MBRAM
    $DiskFormat = $vm.DiskFormat
    $GBDisk = $vm.GBDisk
    $GuestOS = $vm.GuestOS


    #VM build
    New-VM -Name $VMName -VMHost $ESXHost -Datastore $ESXDatastore -NumCpu $NoCPU -MemoryMB $MBRAM -DiskStorageFormat $DiskFormat -DiskGB $GBDisk -GuestId $GuestOS 

    #set the NIC
    New-NetworkAdapter -VM $VMName -NetworkName "VLAN214" -type Vmxnet3
    }

    Thursday, October 11, 2018 10:22 AM

All replies

  • Are you sure there is no error on the "new-networkadapter" command (something along the lines of can't modify VM in its current state)?  You won't be able to modify the VM (ie add a NIC) until it is fully deployed as it will be in a locked state by the current task using it.

    There is a PowerCLI cmdlet called Wait-Task which you can leverage to ensure the VM deploy is complete before continuing to customization tasks against the VM.
    Thursday, October 11, 2018 3:03 PM
  • Hi,

    Just checking in to see if the information provided was helpful.

    Please let us know if you would like further assistance.

    Best Regards,

    Lee


    Just do it.

    Monday, November 5, 2018 9:55 AM