You can modify multiple NIC mapping objects of a customization specification and apply the specification to an existing virtual machine.

Procedure

  1. Get the network adapters of a virtual machine named VM.
    Get-NetworkAdapter VM
    When you apply a customization specification, each network adapter of the customized virtual machine must have a corresponding NIC mapping object. You can correlate network adapters and NIC mapping objects either by their position numbers, or by MAC address.
  2. Create a customization specification named Spec.
    New-OSCustomizationSpec -Type NonPersistent -Name Spec -OSType Windows -Workgroup Workgroup -OrgName Company -Fullname User -ProductKey “valid_key” -ChangeSid -TimeZone "Central European" -NamingScheme VM
  3. Add a new NIC mapping object that uses a static IP address.
    New-OSCustomizationNicMapping -Spec Spec -IpMode UseStaticIP -IpAddress 172.16.1.30 -SubnetMask 255.255.255.0 -DefaultGateway 172.16.1.1 -Dns 172.16.1.1
  4. View the NIC mapping objects and verify that two NIC mapping objects are available.
    Get-OSCustomizationNicMapping -Spec Spec
    The default NIC mapping object is DHCP enabled, and the newly added one uses a static IP address.
  5. Apply the Spec customization specification to the VM virtual machine.
    Get-VM VM | Set-VM -OSCustomizationSpec -Spec Spec
  6. Associate a network adapter from the VMNetwork network with the NIC mapping object that uses DHCP mode.
    $netAdapter = Get-NetworkAdapter VM | where { $_.NetworkName -eq 'VMNetwork' }
    Get-OSCustomizationNicMapping -Spec Spec | where { $_.IPMode -eq 'UseDHCP' } | Set-OSCustomizationNicMapping -NetworkAdapterMac $netAdapter.MacAddress