Link to home
Start Free TrialLog in
Avatar of itnifl
itniflFlag for Norway

asked on

How to use New-SCVirtualNetworkAdapter cmdlet to set a static IP address

Using Hyper-V on 2012R2.

When using New-SCVirtualNetworkAdapter to create a NIC with an static IP address and using the -HardwareProfile option, I assume the IP address is automatically assigned from the static IP pool when the template using the hardware profile is deployed(seems like it, since that seems to work without me specifying an address). But when I am not assigning a new NIC to a hardware profile but to an existing VM that is turned off, it on the other hand does not seem to receive a static IP. The NIC shows up in VMM as for use with static IP, but no IP is assigned.

The code I am using goes like this:

$VMNetwork = Get-SCVMNetwork -VMMServer vmmServerFQDN -Name "VLAN 110 Network" 
$VMSubnet = Get-SCVMSubnet -VMMServer vmmServerFQDN -Name "VLAN 110 Network_Subnet" 

New-SCVirtualNetworkAdapter -VM "VMNameHere" -MACAddress "00:00:00:00:00:00" -MACAddressType Static -Synthetic -EnableVMNetworkOptimization $false -EnableMACAddressSpoofing $false -EnableGuestIPNetworkVirtualizationUpdates $false -IPv4AddressType Static -IPv6AddressType Dynamic -VMSubnet $VMSubnet -VMNetwork $VMNetwork

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itnifl

ASKER

Yes, works nice.