PowerCLI

 View Only
  • 1.  set-network adapter fails from script

    Posted Aug 14, 2009 03:23 PM

    I've got a script that imports some virtual machines and changes the NIC's network label as well. The command to change the network label is

    Get-VM -name $vmName |Get-NetworkAdapter |Set-NetworkAdapter -NetworkName $NETLABEL -Confirm:$FALSE

    Rather oddly this only works some of the time but doesn't error when it has failed. If I run the command manually it works fine all of the time.

    The events for the imported server show the following:

    1. Registered with VirtualCenter

    2. Task: Reconfigure virtual machine

    3. BIOS UUID being changed - this is because the server is a replica of any existing guest

    4. MAC address being changed - ditto

    5. Reconfigure virtual machine.

    I'm wondering if the changing of the MAC and/or UUID is conflicting with the scripted NIC change.

    Any ideas please?

    Thanks



  • 2.  RE: set-network adapter fails from script

    Posted Aug 14, 2009 08:19 PM

    The cmdlets to change the network are correct, provided you are sure the $NETLABEL variable holds a valid networkname in all cases.

    The change of the MAC address is finished before you launch the change network line ?

    You could try listing the current network name before changing it. Just to make sure all is ok.

    Something like this for example

    
    $net = Get-VM <VM-name> | Get-NetworkAdapter
    $net | select Name, NetworkName, MAC
    $net | Set-NetworkAdapter -NetworkName $NETLABEL -Confirm:$false
    
    



  • 3.  RE: set-network adapter fails from script

    Posted Aug 17, 2009 09:18 AM

    I'm positive that $NETLABEL contains a valid network name as it works for the next guest in the list.

    Comparing the events log with that of a guest that did work I see a difference. In the successfully changed guest I see the MAC address being changed twice. The first has the original network label and the second has the new network label. If I put a 5 second or so delay in the script it would work, albeit a little untidy.



  • 4.  RE: set-network adapter fails from script

    Posted Aug 17, 2009 10:13 AM

    I put a little loop that waits for the network label to be what is should be after the cmdlet is run and found it updated correctly on the second run.

    Must be a timing issue somewhere.



  • 5.  RE: set-network adapter fails from script

    Posted Aug 17, 2009 11:23 AM

    You could also use the Wait-Task cmdlet.