Automation

 View Only
  • 1.  Create VM with static MAC address

    Posted Feb 14, 2011 01:11 PM

    Hi All,

    Im trying to create a VM with PowerCLi but im failing to link New-VM with a network addapter??

    I know you can create new network addapter with:

    New-NetworkAdapter -MacAddress 00:50:56:bb:00:13 -Type e1000 -NetworkName "Vlan 6 Virtual Machine"

    But this will just create a nIc card on the server im connected to using

    connect-viserver

    New-VM

    -Name VMSTORE23 -VMHost $esxhost -Datastore $datastore -DiskMB 20000 -MemoryMB 2019 -NumCpu 2

    I think the cdmlet i need to use is -OScustomizationSpec but like i say im strugling to make the connection?

    Has anyone any ideas.

    Thanks in advance for your help.

    Eddie



  • 2.  RE: Create VM with static MAC address

    Posted Feb 14, 2011 01:48 PM

    You should be able to do this as follows

    Get-VM MyVM | Get-NetworkAdapter | Set-NetworkAdapter -MacAddress "00:50:56:bb:00:13"

    Or if you want to add a new NIC you can do

    Get-VM MyVM | Net-NetworkAdapter -MacAddress "00:50:56:bb:00:13" Type e1000 -NetworkName "Vlan 6 Virtual Machine"

    You have to pass the VM, either via the pipeline or via the -VM parameter.



  • 3.  RE: Create VM with static MAC address

    Posted Feb 14, 2011 02:02 PM

    LucD, you are a machine!



  • 4.  RE: Create VM with static MAC address

    Posted Feb 14, 2011 02:15 PM

    New-VM

    -Name VMSTORE23 -VMHost $esxhost -Datastore $datastore -DiskMB 20000 -MemoryMB 2048 -NumCpu 2

    New-NetworkAdapter -VM VMSTORE23 -NetworkName "Virtual Machine Network" -type Vmxnet3 -StartConnected

    This creates a SECOND adapter with the correct settings. I need to create just the single adapter. Is this how you have piped the command. Sorry quite new to powershell, not sure how pipeing works.

    Thanks for your help



  • 5.  RE: Create VM with static MAC address

    Posted Feb 14, 2011 02:30 PM

    When you do your New-VM it will create a NIC that is connected to the portgroup you define with the -NetworkName parameter.

    You pipe the result of the New-VM cmdlet, which is a VM object, to the Get-NetworkAdapter cmdlet to retrieve the NIC object and then you pipe that object to the Set-NetworkAdapter cmdlet to change the MAC address.

    This would look something like this

    New-VM -Name VMSTORE23 -VMHost $esxhost -Datastore $datastore `

      -DiskMB 20000 -MemoryMB 2048 -NumCpu 2 `

      -NetworkName "Virtual Machine Network" | `

    Get-NetworkAdapter | Set-NetworkAdapter  -type Vmxnet3 -StartConnected

    Note the backtick at the end of the first 3 lines, that is a continuation character.




  • 6.  RE: Create VM with static MAC address

    Posted Feb 14, 2011 03:14 PM

    Hi LucD,

    thanks you have been very helpfull. Unfortunatly im still in a bit of a tangle, im using the following commad piping the customization in as your example:

    New-VM -Name VMSTORE23 -VMHost $esxhost -Datastore $datastore -DiskMB 20000 -MemoryMB 2048 -NumCpu 2 -NetworkName "Vlan 6 Virtual Machine Network" | Get-NetworkAdapter | Set-NetworkAdapter -Type Vmxnet3 -MacAddress 00:50:56:bb:00:2b

    But recive the folowwing error:

    2/14/2011 3:10:57 PM Get-NetworkAdapter The pipeline has been stopped.

    At :line:39 char:18

    + Get-NetworkAdapter <<<< | Set-NetworkAdapter -Type Vmxnet3 -MacAddress 00:50:56:bb:00:2b

    2/14/2011 3:10:57 PM Set-NetworkAdapter The MAC address is invalid or is not in the valid range 00:50:56:00:00:00 - 00:50:56:3F:FF:FF.

    At :line:39 char:39

    + Get-NetworkAdapter | Set-NetworkAdapter <<<< -Type Vmxnet3 -MacAddress 00:50:56:bb:00:2b



  • 7.  RE: Create VM with static MAC address
    Best Answer

    Posted Feb 14, 2011 05:11 PM

    You're nearly there, the MAC address has to be specified as a string, place it between quotes.

    New-VM -Name VMSTORE23 -VMHost $esxhost -Datastore $datastore -DiskMB 20000 -MemoryMB 2048 -NumCpu 2 -NetworkName "Vlan 6 Virtual Machine Network" | Get-NetworkAdapter | Set-NetworkAdapter -Type Vmxnet3 -MacAddress "00:50:56:bb:00:2b" -Confirm:$false

    I added the -Confirm parameter, that way you will not be prompted for the change.



  • 8.  RE: Create VM with static MAC address

    Posted Feb 14, 2011 05:24 PM

    Thanks LucD!

    Thats worked a treat!