VMware Cloud Community
Vikassahay
VMware Employee
VMware Employee

wanted to change the Networkadapter type from E1000 to VMXnet3 and retain the IP address.

wanted to change the Networkadapter type from E1000 to VMXnet3 and retain the IP address.

Can any one confirm if this is possible using powercli.

Regards,

Vikas Sahay

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

Not without taking some action inside the guest OS before and after the type change afaik.

A new type is considered by the guest OS as a new NIC.
You can fetch the current settnigs, then change the type and then apply the old settings on the new NIC.

Since Invoke-VMScript is the cmdlet you are looking at, the presence of the VMware Tools is a requirement.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vikassahay
VMware Employee
VMware Employee

Thank you for your quick response.

I have followed the same and did testing in-house for a single virtual machine:

========================

Function Set-WinVMIP ($VM,$GC, $IP, $SNM, $GW){

$netsh = "c:\windows\system32\netsh.exe interface ip set address ""Local Area Connection"" static $IP $SNM $GW 1"

Write-Host "Setting IP address for $VM..."

Invoke-VMScript -VM $VM -GuestCredential $GC -ScriptType bat -ScriptText $netsh

Write-Host "Setting IP address completed."

}

Connect-VIServer -Server 10.106.131.13 -User XXXX -Password XXXX

$ipfetchbackup=""

$VM = Get-VM -Name “virtualmachine name”

$ipfetch=$vm.ExtensionData.Guest.Net.ipConfig.ipAddress.ipAddress

foreach ($IP in $ipfetch){

$pattern = "^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$"

if($IP -match $pattern){

Write-Host "id to be assign "+ $IP.ToString()

$ipfetchbackup=$IP.ToString()

}

}

Stop-VM -VM $VM

$vm.PowerState

$VM = Get-VM -Name " virtualmachine name"

Get-VM $VM | Get-NetworkAdapter | Set-NetworkAdapter -type "Vmxnet3"

Start-VM -VM $VM

start-sleep -Seconds 60

$GuestCred = $Host.UI.PromptForCredential("Please enter credentials", "Enter Guest credentials for $VM", "", "")

$IP = $ipfetchbackup

$SNM = "255.255.255.0"

$GW = "192.168.0.1"

Set-WinVMIP $VM $GuestCred $IP $SNM $GW

===================================================

I got the response from customer for this as :

Its Powered off the VM and changed the Network Adapter from E1000 to VMXNet3 then powered On the VM but its unable to assign the IP. Post reboot its asking Guest OS credential to assign IP address and if we entered ours domain credential then its giving the below error.

I hope its because VM powered on without IP and its out of enterprise Network so its unable to communicate DC for authentication.

Any feedback in this regard.

Regards,

Vikas Sahay

Reply
0 Kudos
LucD
Leadership
Leadership

Did you use the credentials from a local account?
With an AD account it won't work (since there is no network yet).


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vikassahay
VMware Employee
VMware Employee

when I tested locally I used Administrator@vsphere.local account I am not sure which account customer used. Will that makes any difference. Also confirm me if the above script is correct way to change the network type and retain the IP address.

Regards,

Vikas Sahay

Reply
0 Kudos
Vikassahay
VMware Employee
VMware Employee

Also let me know what do you mean by "Did you use the credentials from a local account?"

regards,

vikas Sahay

Reply
0 Kudos
LucD
Leadership
Leadership

You need to use an account that has the required privileges on the station to make changes to the network settings inside the guest OS.

An account that is defined on the machine itself (local administrator) vs an AD account, which is defined on the DCs.

And definitely not an account from the vSphere SSO.

Update: we are talking about the account that is used on the GuestCRedential parameter of the Invoke-VMScript cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos