VMware Cloud Community
dimwoo
Contributor
Contributor
Jump to solution

Error running set-vmguestnetworkinterface

Hi,

I'm using Powercli 5.1 and get-vmguestnetworkinginterface is working ok in this format:

Get-VMGuestNetworkInterface -VM as99.pool.local -GuestUser user1 -GuestPassword password

VM              Name                      IP              IPPolicy   SubnetMask

--              ----                      --              --------   ----------

AS01.pool.lo... Local Area Connection     10.1.80.11    Static     255.255.255.0

AS01.pool.lo... isatap.{FA9A7712-96EE-...                 Static

AS01.pool.lo... Teredo Tunneling Pseud...                 Static

But when I run set-vmguestnetworkinginterface I get the following error:

$nic = "Local Area Connection"

Set-VMGuestNetworkInterface -VmGuestNetworkInterface $nic -VM as991.pool.local -Ip 10.1.80.99 -Netmask 255.255.255.0 -Gateway 10.1.80.111 -GuestUser user1 -GuestPassword password

Set-VMGuestNetworkInterface : Cannot bind parameter 'VmGuestNetworkInterface'. Cannot convert the "Local Area Connection" value o
f type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.VM.Guest.VMGuestNetworkInterface".
At line:1 char:53
+ Set-VMGuestNetworkInterface -VmGuestNetworkInterface <<<<  $nic -VM as99.pool.local -Ip 10.1.80.99 -Netmask 255.255.255
.0 -Gateway 10.1.80.111 -GuestUser user1 -GuestPassword password.
    + CategoryInfo          : InvalidArgument: (:) [Set-VMGuestNetworkInterface], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetVmGuestNetworkInter
   face

Problem seems to be parsing the "Local Area Connection" value. I have tried entering it in the commandline with or without single or double quotes and neither works. It always responds "Cannot convert the "Local" value of type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.VM.Guest.VMGuestNetworkInterface"".

What am I doing wrong?

0 Kudos
1 Solution

Accepted Solutions
Grzesiekk
Expert
Expert
Jump to solution

Hi there,

  when you retrieve the guest network interface with get-vmguestnetworkinterface then everything is written in this object:

VMId
VM
NetworkAdapter
SubnetMask
NicId
NetworkAdapterId
Name
IPPolicy
Ip
Dns
DefaultGateway
Description
Mac
RouteInterfaceId
Uid
DnsPolicy
WinsPolicy
Wins

Those are properties of the guest network interface. As you can see it holds information frim which VM this interface comes.

when you do:

get-vm my_vm_name|Get-VMGuestNetworkInterface |?{$_.name -eq "Local Area connection"}

The you will receive this object , the guest netowwork interface object,. It will show the vmid,vm name etc... in its properties

for example do this

$nic=get-vm my_vm_name|Get-VMGuestNetworkInterface |?{$_.name -eq "Local Area connection"}

then

$nic | format-list *

You will be surprised by how much info this object holds.

All this infromation is passsed then to the set-vmguestnetworkinterface

This cmdlet EXPECTS to see on the input this kind of object , a guest network interface object:

-VmGuestNetworkInterface <VMGuestNetworkInterface[]>
        Specify the guest network interface you want to configure.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?       true (ByValue)
        Accept wildcard characters?  true

Since it expects that kind of object you have to deliver it this. So best way to deliver that is to grab that network interface object that you want to change by using: get-vmguestnetworkinterface

This describes that it is mandatory to provide this object.  Since it accepts value from pipeline you can do

get the desired interface | set-the desired interface

The error you are receiving is correct because you lost 2 parameters in the command line such as:

C:\PS>Set-VMGuestNetworkInterface -VMGuestNetworkInterface $vmGuestNetworkInterface -HostUser Admin -HostPassword Pass01 -GuestUser User -GuestPassword Pass02 -Netmask 255.255.255.255 -Gateway 10.23.112.58

If you put there the : root and root password from the esx  it will work or the VC creds, as per manual

-HostUser <String>
     Specify the user name you want to use for authenticating with the host. You need to specify host credentials only if the version of the vCenter Server or ESX you are authe
     nticating with is earlier than 4.0, or the VIX version you have installed is earlier than 1.10.

You can also build yourself a credential object because this command supports it

-GuestCredential <PSCredential>
    Specify a PSCredential object that contains credentials for authenticating with the guest OS. Do not use this parameter if the -GuestUser and -GuestPassword parameters are
     used.

-HostCredential <PSCredential>
     Specify a PSCredential object that contains credentials for authenticating with the host. Do not use this parameter if the -HostUser and -HostPassword parameters are used.
      You need to specify host credentials only if the version of the vCenter Server or ESX you are authenticating with is earlier than 4.0, or the VIX version you have install
     ed is earlier than 1.10.

$guestcred=get-credential

$hostcred=get-credential

Put proper credentials for the guest OS, and the for host

then

Set-VMGuestNetworkInterface -VMGuestNetworkInterface $vmGuestNetworkInterface -HostCredential $hostcred -GuestCredential $guestcred -Netmask 255.255 .255.255 -Gateway 10.23.112.58

Then it will work, assuing you have your guest network inferface stored in $vmGuestNetworkInterface

In my opinion the easiest way is to send that info via the pipeline

so

get-vm "your_VM"|Get-VMGuestNetworkInterface  -hostcredential $hostcred -guestcredential $guestcred|?{$_.name -eq "Local Area connection"} | set-vmguestnetworkinterface -hostcredential $hostcred -guestcredential $guestcred -Netmask 255.255.0.0 -Gateway New.IP.ADD.RES

For example Smiley Wink

by the way

===========

Do I have to run the whole thing as one command? e.g.

$nic=Get-VMGuestNetworkInterface  -VM as01.pool.local -GuestUser user1 -GuestPassword password | ?  {$_.name -eq "Local Area Connection"} | Set-VMGuestNetworkInterface  -VMGuestNetworkInterface $nic -Guest User user1 -GuestPassword password  -Ip 10.1.80.99 -Netmask 255.255.255.0 -Gateway 10.1.80.111

=========

This is not correct

That should be 2 lines

if you use additional variable to hold the guestnic

$nic=Get-VMGuestNetworkInterface  -VM as01.pool.local -GuestUser  user1 -GuestPassword password | ?  {$_.name -eq "Local Area Connection"}

That was 1 line to assign variable $nic to a guestnetworkinterface object

Set-VMGuestNetworkInterface  -VMGuestNetworkInterface $nic -Guest  User user1 -GuestPassword password  -Ip 10.1.80.99 -Netmask  255.255.255.0 -Gateway 10.1.80.111

And that was second line which uses the $nic variable that you have filled previously with that object.

if you want to use 1 line do not use the $nic var , but put everything through the pipeline

get-vm "your_VM"|Get-VMGuestNetworkInterface  -hostcredential $hostcred  -guestcredential $guestcred|?{$_.name -eq "Local Area connection"} |  set-vmguestnetworkinterface -hostcredential $hostcred -guestcredential  $guestcred -Netmask 255.255.0.0 -Gateway New.IP.ADD.RES

This was 1 long line using the hostcredential and guestcredential PScredential objects in order to authorize on host and in guest.

======

Even then set-vmguestnetworkintererface is not being told which VM to modify....?

======

set-vmguestnetworkinterface IS told which vm's network interface it needs modify , By passing the CORRECT interface to it.

and when you are getting the interface , then get only the desired interface , from desired vm, correct ?

Then again this object also has INSIDE of it, information to which vm it is related to.

Please let me know if you need any other explanation

--- @blog https://grzegorzkulikowski.info

View solution in original post

0 Kudos
7 Replies
dimwoo
Contributor
Contributor
Jump to solution

PS:   VM is Windows 2008 R2 standard, 64-bit. VMTools has been updated and, as above, works for get-vmguestnetworkinginterface.

0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

Hello,

  please have in mind that you need to give first this object VMGuestNetworkInterface:

PARAMETERS
    -VmGuestNetworkInterface <VMGuestNetworkInterface[]>
        Specify the guest network interface you want to configure.

So

Get-VMGuestNetworkInterface -VM as99.pool.local -GuestUser user1 -GuestPassword password | ? ${$_.name -eq "Local Area Connection"} | Set-VMGuestNetworkInterface -Ip 10.1.80.99 -Netmask 255.255.255.0 -Gateway  10.1.80.111 -GuestUser user1 -GuestPassword password

So you were very close :

$nic = "Local Area Connection"

instead of nic like the name of the connection you should have here the configuration of guestnetwork interface so if you would like to store it in variable

$nic=Get-VMGuestNetworkInterface -VM as99.pool.local -GuestUser user1 -GuestPassword password | ? ${$_.name -eq "Local Area Connection"}

Now if you have this in $nic, then you can make the set exactly in the same way like get-help for set-vmguestnetworkinterface says

C:\PS>Set-VMGuestNetworkInterface -VMGuestNetworkInterface $nic -HostUser Admin -HostPassword Pass01 -GuestUser User -GuestPassword Pass02 -Netmask 255.255.255.255 -Gateway 10
.23.112.58

Regards,

Greg

--- @blog https://grzegorzkulikowski.info
dimwoo
Contributor
Contributor
Jump to solution

Hi Greg, thanks for your reply.

I am not familiar with ? ${$_.name -eq "Local Area Connection"but I guess this is filtering the output of Get-VMGuestNetworkInterface to only show the data for "Local Area Connection".

However I am getting an error:

$nic=Get-VMGuestNetworkInterface -VM as99.pool.local -GuestUser user1 -GuestPassword password | ? ${$_.name -eq "Local Area Connection"}

Where-Object : Cannot bind argument to parameter 'FilterScript' because it is null.
At line:1 char:121
+ $nic=Get-VMGuestNetworkInterface -VM as99.pool.local -GuestUser user1 -GuestPassword password | ? <<<<
${$_.name -eq "Local Area Connection"}
    + CategoryInfo          : InvalidData: (:) [Where-Object], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.WhereObjectCommand

(Note: I am using different user id and password that "user1" and "password" so char:121 will not be the same. But the problem appears to be the ${$_.name -eq section.)

Instead of cutting and pasting your example I have retyped the command so I know the characters are correct.

Can you advise?

0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

I am sorry for this, i made a typo there.

$nic=Get-VMGuestNetworkInterface -VM as99.pool.local -GuestUser  user1 -GuestPassword password | ? {$_.name -eq "Local Area Connection"}

this should be good

This:


$nic=Get-VMGuestNetworkInterface -VM as99.pool.local -GuestUser  user1 -GuestPassword password

Would retrieve all guest networkinterfaces , not only localareconnection

Since we would like to set something only on the Localareaconection we need to first filter this out.

This part has all networkinterfaces objects (multiple) -> it goes to pipeline where we do filtering| ? {$_.name -eq "Local Area Connection"}

After pipeline we check all objects (all interfaces) and we select only those where the object property called "name" equals to "Local Area Connection"

i am sorry for writing with aliases , you could also rewrite it to:

| where-object {$_.name -eq "Local Area Connection"}

? is the alias for where-object

Let me know if you need any other explanation to this.

Greg

--- @blog https://grzegorzkulikowski.info
dimwoo
Contributor
Contributor
Jump to solution

Hi Greg,

Yes, removing the extra $ works. Thanks!

But there's something else I do not understand. The get-help for set-vmguestnetworkinterface does not include the name of the VM. How does it know which VM to run the command against?

SYNTAX
    Set-VMGuestNetworkInterface -VmGuestNetworkInterface <VMGuestNetworkInterface[]> [-WinsPolicy <DhcpPolicy>] [-Wins <String[]>
    ] [-DnsPolicy <DhcpPolicy>] [-Dns <String[]>] [-IPPolicy <DhcpPolicy>] [[-Gateway] <Object>] [[-Netmask] <String>] [[-Ip] <IP
    Address>] [-ToolsWaitSecs <Int32>] [-GuestPassword <SecureString>] [-GuestUser <String>] [-GuestCredential <PSCredential>] [-
    HostPassword <SecureString>] [-HostUser <String>] [-HostCredential <PSCredential>] [-WhatIf] [-Confirm] [<CommonParameters>]

The example given is:  

C:\PS>Set-VMGuestNetworkInterface -VMGuestNetworkInterface $vmGuestNetworkInterface -GuestUser User -GuestPassword Pass02 -Netmask 255.255.255.255 -Gateway 10.23.112.58 

If I run the folloowing from the command line I get a permissions issue:

Set-VMGuestNetworkInterface -VMGuestNetworkInterface $nic -GuestUser user1 -GuestPassword password -Ip 10.1.80.99 -Netmask 255.255.255.0 -Gateway 10.1.80.111


Set-VMGuestNetworkInterface : 08/10/2012 12:02:49    Set-VMGuestNetworkInterface        "Error occured while configuring the netw

ork:'The requested operation requires elevation (Run as administrator).

Access is denied.

The requested operation requires elevation (Run as administrator).

But which VM is is trying to change the network settings on?

Do I have to run the whole thing as one command? e.g. 

$nic=Get-VMGuestNetworkInterface -VM as01.pool.local -GuestUser user1 -GuestPassword password | ? {$_.name -eq "Local Area Connection"} | Set-VMGuestNetworkInterface -VMGuestNetworkInterface $nic -Guest User user1 -GuestPassword password -Ip 10.1.80.99 -Netmask 255.255.255.0 -Gateway 10.1.80.111

Even then set-vmguestnetworkintererface is not being told which VM to modify....?

0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

Hi there,

  when you retrieve the guest network interface with get-vmguestnetworkinterface then everything is written in this object:

VMId
VM
NetworkAdapter
SubnetMask
NicId
NetworkAdapterId
Name
IPPolicy
Ip
Dns
DefaultGateway
Description
Mac
RouteInterfaceId
Uid
DnsPolicy
WinsPolicy
Wins

Those are properties of the guest network interface. As you can see it holds information frim which VM this interface comes.

when you do:

get-vm my_vm_name|Get-VMGuestNetworkInterface |?{$_.name -eq "Local Area connection"}

The you will receive this object , the guest netowwork interface object,. It will show the vmid,vm name etc... in its properties

for example do this

$nic=get-vm my_vm_name|Get-VMGuestNetworkInterface |?{$_.name -eq "Local Area connection"}

then

$nic | format-list *

You will be surprised by how much info this object holds.

All this infromation is passsed then to the set-vmguestnetworkinterface

This cmdlet EXPECTS to see on the input this kind of object , a guest network interface object:

-VmGuestNetworkInterface <VMGuestNetworkInterface[]>
        Specify the guest network interface you want to configure.

        Required?                    true
        Position?                    named
        Default value
        Accept pipeline input?       true (ByValue)
        Accept wildcard characters?  true

Since it expects that kind of object you have to deliver it this. So best way to deliver that is to grab that network interface object that you want to change by using: get-vmguestnetworkinterface

This describes that it is mandatory to provide this object.  Since it accepts value from pipeline you can do

get the desired interface | set-the desired interface

The error you are receiving is correct because you lost 2 parameters in the command line such as:

C:\PS>Set-VMGuestNetworkInterface -VMGuestNetworkInterface $vmGuestNetworkInterface -HostUser Admin -HostPassword Pass01 -GuestUser User -GuestPassword Pass02 -Netmask 255.255.255.255 -Gateway 10.23.112.58

If you put there the : root and root password from the esx  it will work or the VC creds, as per manual

-HostUser <String>
     Specify the user name you want to use for authenticating with the host. You need to specify host credentials only if the version of the vCenter Server or ESX you are authe
     nticating with is earlier than 4.0, or the VIX version you have installed is earlier than 1.10.

You can also build yourself a credential object because this command supports it

-GuestCredential <PSCredential>
    Specify a PSCredential object that contains credentials for authenticating with the guest OS. Do not use this parameter if the -GuestUser and -GuestPassword parameters are
     used.

-HostCredential <PSCredential>
     Specify a PSCredential object that contains credentials for authenticating with the host. Do not use this parameter if the -HostUser and -HostPassword parameters are used.
      You need to specify host credentials only if the version of the vCenter Server or ESX you are authenticating with is earlier than 4.0, or the VIX version you have install
     ed is earlier than 1.10.

$guestcred=get-credential

$hostcred=get-credential

Put proper credentials for the guest OS, and the for host

then

Set-VMGuestNetworkInterface -VMGuestNetworkInterface $vmGuestNetworkInterface -HostCredential $hostcred -GuestCredential $guestcred -Netmask 255.255 .255.255 -Gateway 10.23.112.58

Then it will work, assuing you have your guest network inferface stored in $vmGuestNetworkInterface

In my opinion the easiest way is to send that info via the pipeline

so

get-vm "your_VM"|Get-VMGuestNetworkInterface  -hostcredential $hostcred -guestcredential $guestcred|?{$_.name -eq "Local Area connection"} | set-vmguestnetworkinterface -hostcredential $hostcred -guestcredential $guestcred -Netmask 255.255.0.0 -Gateway New.IP.ADD.RES

For example Smiley Wink

by the way

===========

Do I have to run the whole thing as one command? e.g.

$nic=Get-VMGuestNetworkInterface  -VM as01.pool.local -GuestUser user1 -GuestPassword password | ?  {$_.name -eq "Local Area Connection"} | Set-VMGuestNetworkInterface  -VMGuestNetworkInterface $nic -Guest User user1 -GuestPassword password  -Ip 10.1.80.99 -Netmask 255.255.255.0 -Gateway 10.1.80.111

=========

This is not correct

That should be 2 lines

if you use additional variable to hold the guestnic

$nic=Get-VMGuestNetworkInterface  -VM as01.pool.local -GuestUser  user1 -GuestPassword password | ?  {$_.name -eq "Local Area Connection"}

That was 1 line to assign variable $nic to a guestnetworkinterface object

Set-VMGuestNetworkInterface  -VMGuestNetworkInterface $nic -Guest  User user1 -GuestPassword password  -Ip 10.1.80.99 -Netmask  255.255.255.0 -Gateway 10.1.80.111

And that was second line which uses the $nic variable that you have filled previously with that object.

if you want to use 1 line do not use the $nic var , but put everything through the pipeline

get-vm "your_VM"|Get-VMGuestNetworkInterface  -hostcredential $hostcred  -guestcredential $guestcred|?{$_.name -eq "Local Area connection"} |  set-vmguestnetworkinterface -hostcredential $hostcred -guestcredential  $guestcred -Netmask 255.255.0.0 -Gateway New.IP.ADD.RES

This was 1 long line using the hostcredential and guestcredential PScredential objects in order to authorize on host and in guest.

======

Even then set-vmguestnetworkintererface is not being told which VM to modify....?

======

set-vmguestnetworkinterface IS told which vm's network interface it needs modify , By passing the CORRECT interface to it.

and when you are getting the interface , then get only the desired interface , from desired vm, correct ?

Then again this object also has INSIDE of it, information to which vm it is related to.

Please let me know if you need any other explanation

--- @blog https://grzegorzkulikowski.info
0 Kudos
dimwoo
Contributor
Contributor
Jump to solution

Hi Greg,

Thank you, what an excellent reply, I have learned a lot. I was still thinking in terms of dos batch, did not know that powershell was hiding the full data being returned.

Also have never used get-credential before, that will save a lot of typing!

Everything now works, so I have marked this as answered. BUT I still cannot get the set-vmguestnetworkinterface command to complete as I do not have a Host user / password. I am working for a 3rd party and it is not easy to get logins direct to the ESX hosts. I posted on this in this forum a week or two ago. As a result one of our ESX hosts was upgraded to ESX 4 updated 4, which is supposed to allow you to run these commands without host credentials. After doing that (and upgrading to Powercli 5.1) get-vmguestnetworkinterface worked without host credentials. But now I have reached the correct way to use set-vmguestnetworkinterface it is asking for them again.

I have an AD domain  user with full admin rights through VSphere client, but that doesn't work as host credential. Do you have any suggestions, or should I start another thread?

Thanks again, you expanded my mind....

0 Kudos