bsvinis
Contributor
Contributor

VmGuestNetworkInterface Question

Jump to solution

Greetings,

I have the following snippet of code:

do { $vm = Get-VM -Name P4-Test-Clone | Get-View } while($vm.guest.ToolsStatus -ne 'toolsOk')

$NetworkAdapter = Get-NetworkAdapter -VM P4-Test-Clone

echo $vm.guest.ToolsStatus

Set-NetworkAdapter -NetworkAdapter $NetworkAdapter -NetworkName 'VM Network 2501' -StartConnected $true -Connected $true -Confirm:$false

echo $vm.guest.ToolsStatus

$GuestInterface = Get-VMGuestNetworkInterface -VM P4-Test-Clone -HostUser $hu -HostPassword $hp -GuestUser $gu -GuestPassword $gp

echo $vm.guest.ToolsStatus

Set-VMGuestNetworkInterface -HostUser $hu -HostPassword $hp -GuestUser $gu -GuestPassword $gp -VMGuestNetworkInterface $GuestInterface -IP 10.25.1.116 -Netmask 255.255.255.0 -Gateway 10.25.1.254

$vm.guest.ToolsStatus

Which ends up returning:

MacAddress       : 00:50:56:8e:00:3c

WakeOnLanEnabled : True

NetworkName      : VM Network 2501

Type             : Vmxnet3

ParentId         : VirtualMachine-vm-471

Parent           : P4-Test-Clone

Uid              : /VIServer=mgmt\bsvinis@dci-vc1:443/VirtualMachine=VirtualMac

                   hine-vm-471/NetworkAdapter=4000/

ConnectionState  : Connected:True

ExtensionData    : VMware.Vim.VirtualVmxnet3

Id               : VirtualMachine-vm-471/4000

Name             : Network adapter 1

toolsOk

Get-VMGuestNetworkInterface : 2/2/2011 6:16:31 PM    Get-VMGuestNetworkInterfac

e        While performing operation 'Wait to connect to guest's VMware tools on

VM 'P4-Test-Clone'' the following error occured: 'Timeout error while waiting

for VMware Tools to start in the guest'

At C:\Users\bsvinis\Desktop\test.ps1:9 char:46

+ $GuestInterface = Get-VMGuestNetworkInterface <<<<  -VM P4-Test-Clone -HostUs

er root -HostPassword Cisco12345 -GuestUser Administrator -GuestPassword Cisco1

2345

    + CategoryInfo          : OperationTimeout: (:) [Get-VMGuestNetworkInterfa

   ce], VimException

    + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_VixWaitForJob_VixErr

   or,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVmGuestNetworkInterface

toolsOk

Set-VMGuestNetworkInterface : Cannot bind argument to parameter 'VmGuestNetwork

Interface' because it is null.

At C:\Users\bsvinis\Desktop\test.ps1:11 char:144

+ Set-VMGuestNetworkInterface -HostUser root -HostPassword Cisco12345 -GuestUse

r Administrator -GuestPassword Cisco12345 -VMGuestNetworkInterface <<<<  $Guest

Interface -IP 10.25.1.116 -Netmask 255.255.255.0 -Gateway 10.25.1.254

    + CategoryInfo          : InvalidData: (:) [Set-VMGuestNetworkInterface],

   ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,V

   Mware.VimAutomation.ViCore.Cmdlets.Commands.SetVmGuestNetworkInterface

toolsOk

I have highlighted the areas that I have a question about. Mainly, I'm having the script clone the VM, wait until tools status is okay and then try to configure networking. However, it seems that VMGuestNetworkInterface is still having a problem connecting to the tools on the client. If I wait a while longer (30-60 seconds) then the command runs fine.

Any help is most appreciated.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

The ToolsStatus property is not a good point to determine if the OS in your guest is fully started.

It only tells you that VMware Tools service was started in the guest's OS.

The Get-VMGuestNetworkInterface cmdlet is based on a BAT file (for Windows guests) that uses the ipconfig (and sometimes the netsh command) command to retrieve information about the NICs known in the guest's OS. Check out the GetVmGuestNetworkInterface_WindowsGuest.bat file in the vSphere PowerCLI\Scripts folder.

The BAT file is transmitted to guest with some VIX APIs.

The first message you see seems to indicate that this communication through VIX to the guest's OS is not established yet.

The 2nd message, the Set-VMGuestNetworkInterface cmdlet, is the consequence of the failure of the Get-VMGuestNetworkInterface cmdlet. Since that one failed, it didn't return any data and hence $GuestInterface is $null.

The easiest solution is to place a 'sleep 60' line before the Get-VMGuestNetworkInterface

Another solution could be to use WMI to query the guest's OS.

But since you are configuring the guest's NICs that is no option for what you are trying to do.


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

View solution in original post

0 Kudos
1 Reply
LucD
Leadership
Leadership

The ToolsStatus property is not a good point to determine if the OS in your guest is fully started.

It only tells you that VMware Tools service was started in the guest's OS.

The Get-VMGuestNetworkInterface cmdlet is based on a BAT file (for Windows guests) that uses the ipconfig (and sometimes the netsh command) command to retrieve information about the NICs known in the guest's OS. Check out the GetVmGuestNetworkInterface_WindowsGuest.bat file in the vSphere PowerCLI\Scripts folder.

The BAT file is transmitted to guest with some VIX APIs.

The first message you see seems to indicate that this communication through VIX to the guest's OS is not established yet.

The 2nd message, the Set-VMGuestNetworkInterface cmdlet, is the consequence of the failure of the Get-VMGuestNetworkInterface cmdlet. Since that one failed, it didn't return any data and hence $GuestInterface is $null.

The easiest solution is to place a 'sleep 60' line before the Get-VMGuestNetworkInterface

Another solution could be to use WMI to query the guest's OS.

But since you are configuring the guest's NICs that is no option for what you are trying to do.


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

View solution in original post

0 Kudos