13 Replies Latest reply on May 5, 2010 5:35 PM by donvito213

    Change VM IP Address

    DroppedAtBirth Enthusiast

       

      I am trying to use the example Change IP powershell on Managing VMware with PowerShell FAQ but keep getting the same error.

       

       

      The term 'Find-EntityView' is not recognized as a cmdlet, function, operable program, or script file. Verify the term a nd try again.

       

       

      Any better examples or can someone tell me what I may be missing?  All I am changing from the Example is the values that is has in red.

       

       

        • 1. Re: Change VM IP Address
          Master

          Hi, there was some old stuff in the FAQ that I have just updated. Could you try again?

          • 2. Re: Change VM IP Address
            DroppedAtBirth Enthusiast

             

            Tried the new sample, changing out he "<Target IP Address>"  with the new IP and "Test" with the VM Name.  Getting the following error.

             

             

            Unexpected token 'vmclonespec' in expression or statement.

             

             

             

             

             

            More Info

             

             

            Believe i am running latest toolkit "VMware VI Toolkit for Windows 1.0 build 113525" is what is reported in ps.

             

             

            • 3. Re: Change VM IP Address
              DroppedAtBirth Enthusiast

              Does anyone have a working example of change IP?

              • 4. Re: Change VM IP Address
                donvito213 Novice

                Hi There,

                 

                I'm also using this script to try and configure IP address on a newly deployed VM (powered off) and ran into this exception which looks like it happens after this line:

                 

                $vmmor.CloneVM_Task($target.MoRef ,$name, $vmclonespec )

                Exception calling "CloneVM_Task" with "3" argument(s): "The operation is not supported on the object." At line:1 char:20 + $vmmor.CloneVM_Task <<<< ($target.MoRef ,$name, $vmclonespec )     + CategoryInfo          : NotSpecified: ( [], MethodInvocationException     + FullyQualifiedErrorId : DotNetMethodException

                Any ideas? I'm using this script and new to powershell and VI Toolkit

                 

                Thanks in advance!

                • 5. Re: Change VM IP Address
                  LucD Guru
                  User ModeratorsCommunity WarriorsvExpert

                  That's a rather old post.

                   

                  In the latest PowerCLI build you can find the Set-VMGuestNetworkInterface cmdlet.

                  Perhaps that could help you ?

                  Note that it only works for Windows 2003 and up and RHEL 5.

                   

                   

                   

                   

                  ____________

                  Blog: LucD notes

                  Twitter: lucd22

                  • 6. Re: Change VM IP Address
                    donvito213 Novice

                    Hi LucD,

                     

                    Thanks for your reply

                     

                    I downloaded and installed VMWare vSphere PowerCLI (VMware-Vim4PS-1.5.0-142961) on my PC running Windows 7 Enterprise which also has PowerShell included by Windows.

                     

                    I open the "VI Toolkit", connect to the ESX host that is hosting the newly deployed VM as:

                     

                    Connect-VIServer <server_name> -User <username> -Password <password>

                     

                    But looks like the cmdlet "Set-VMGuestNetworkInterface" doesn't exist. I only see the combination of "Set-VMHost... " but not for "guest". Am I overlooking something? Or is it because I'm not running Windows 2003 or RHEL5? Please let me know.

                     

                    Thanks,

                    donvito213

                    • 7. Re: Change VM IP Address
                      RvdNieuwendijk Virtuoso
                      User ModeratorsvExpert

                      You installed an old version. The latest version is VMware-Vim4PS-4.0.1-208462. You can download it from http://www.vmware.com/go/powercli. If you have installed that version and run the cmdlet Get-PowerCLIVersion you should get the next output:

                       

                      [vSphere PowerCLI] C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-PowerCLIVersion
                      
                      PowerCLI Version
                      ----------------
                      VMware vSphere PowerCLI 4.0 U1 build 208462
                      

                       

                      Robert

                      • 8. Re: Change VM IP Address
                        donvito213 Novice

                        Thanks Robert! I didn't realize I got an older version of PowerCLI; now I have the current version.

                         

                        Now I'm able to see the cmdlet set-vmguestnetworkinterface but running into problems trying to configure an IP address to eth0 interface of a Linux VM that has eth0, eth1, and eth2 interfaces:

                         

                        PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> get-vm <*****> |

                        Get-VMGuestNetworkInterface -HostUser <***> -HostPassword <**> -GuestUser <***> -GuestPassword <*****>

                         

                         

                        VMId             : VirtualMachine-368

                        SubnetMask       :

                        NicId            : VirtualMachine-368/4000

                        Name             : eth0

                        IPPolicy         : Dhcp

                        Ip               :

                        Dns              : {##.###.###.###, ##.##.##.##}

                        DefaultGateway   :

                        Description      : Ethernet

                        Mac              : ######

                        RouteInterfaceId : eth0

                        DnsPolicy        : Dhcp

                        WinsPolicy       :

                        Wins             :

                         

                        VMId             : VirtualMachine-368

                        SubnetMask       :

                        NicId            : VirtualMachine-368/4001

                        Name             : eth1

                        IPPolicy         : Dhcp

                        Ip               :

                        Dns              : {#######}

                        DefaultGateway   :

                        Description      : Ethernet

                        Mac              : ######

                        RouteInterfaceId : eth1

                        DnsPolicy        : Dhcp

                        WinsPolicy       :

                        Wins             :

                         

                        VMId             : VirtualMachine-368

                        SubnetMask       :

                        NicId            : VirtualMachine-368/4002

                        Name             : eth2

                        IPPolicy         : Dhcp

                        Ip               :

                        Dns              : {#####}

                        DefaultGateway   :

                        Description      : Ethernet

                        Mac              : ######

                        RouteInterfaceId : eth2

                        DnsPolicy        : Dhcp

                        WinsPolicy       :

                        Wins             :

                         

                        VMId             : VirtualMachine-368

                        SubnetMask       : 255.0.0.0

                        NicId            :

                        Name             : lo

                        IPPolicy         : Dhcp

                        Ip               : 127.0.0.1

                        Dns              : {######}

                        DefaultGateway   :

                        Description      : Local Loopback

                        Mac              :

                        RouteInterfaceId : lo

                        DnsPolicy        : Dhcp

                        WinsPolicy       :

                        Wins             :

                         

                         

                         

                        PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> Set-VMGuestNetwor

                        kInterface -VmGuestNetworkInterface eth0 -vm <***> -GuestUser <**> -GuestPassw

                        ord <***> -ip <***> -netmask <***> -gateway <****>

                        Set-VMGuestNetworkInterface : Cannot bind parameter 'VmGuestNetworkInterface'. Cannot convert the "eth0" value of type "System.String" to type "VMware.VimAuto mation.Types.VMGuestNetworkInterface". At line:1 char:53 + Set-VMGuestNetworkInterface -VmGuestNetworkInterface <<<<  eth0 -vm <**> - GuestUser <**> -GuestPassword <**> -ip <*> -netmask <*> -gateway <**>     + CategoryInfo          : InvalidArgument: ( [Set-VMGuestNetworkInterfac    e], ParameterBindingException     + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomat    ion.VimAutomation.Commands.SetVmGuestNetworkInterface

                         

                        Anyone have any ideas how to resolve this exception? Thanks in advance!

                        • 9. Re: Change VM IP Address
                          RvdNieuwendijk Virtuoso
                          User ModeratorsvExpert

                          There are more people with the same problem in thread Get-VMGuestNetworkInterface question. The cause of your problem might be that the networkinterface is not connected. Otherwise take a look at a different solution in this blogpost by Alan Renouf:

                          PowerCLI: Changing a VM IP Address with Invoke-VMScript.

                           

                          Regards, Robert

                          • 10. Re: Change VM IP Address
                            donvito213 Novice

                             

                            Hi Robert,

                             

                             

                            Sorry for replying late. I am still strugglling to get this command to work without getting errors:

                             

                             

                             

                             

                             

                            PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; $vmGuestNetworkIn

                            terface = Get-VM &lt;**&gt; | `Get-VMGuestNetworkInterface -HostUser &lt;****&gt;-Host

                            Password &lt;**&gt; -GuestUser &lt;*&gt; -GuestPassword &lt;**&gt;| `Where-Object { $_

                            .Name -eq "eth0" }

                            WARNING: The version of VMware Tools on VM 'clayton-lnx' is out of date and may cause Copy-VMGuestFile to work improperly.

                            Get-VMGuestNetworkInterface : 4/30/2010 4:09:10 PM    Get-VMGuestNetworkInterfa ce    A6A57C46-E9EE-419D-B8FE-B2E745D28B2E    Unable to parse script output.

                             

                            At line:1 char:77 + $vmGuestNetworkInterface = Get-VM clayton-lnx | `Get-VMGuestNetworkInterface &lt;&lt;&lt;&lt;  -HostUser root -HostPassword netscreen -GuestUser &lt;****&gt; -GuestPassword &lt;***&gt;  | `Where-Object { $_.Name -eq "eth0" }     + CategoryInfo          : InvalidArgument: ( [Get-VMGuestNetworkInterfac    e], ViError     + FullyQualifiedErrorId : Client20_VmHostServiceImpl_GetVmGuestNetworkInte    rface_UnableToParse,VMware.VimAutomation.VimAutomation.Commands.GetVmGuest   NetworkInterface

                             

                             

                            Even running a more basic command still yields the same exact error of "Unable to parse script output":

                             

                            PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; Get-VM &lt;*&gt; | Get-VMGuestNetworkInterface -HostUser &lt;*&gt; -HostPassword &lt;*&gt; -GuestUser &lt;*&gt; -GuestPassword &lt;**&gt;

                            Any other ideas? 

                             

                             

                            • 11. Re: Change VM IP Address
                              RvdNieuwendijk Virtuoso
                              User ModeratorsvExpert

                              There are more people facing the same problem in thread Get-VMGuestNetworkInterface question. The cause of your problem might be that the networkinterface is not connected. Otherwise take a look at a different solution by Alan Renouf:

                              PowerCLI: Changing a VM IP Address with Invoke-VMScript.

                               

                              Regards, Robert

                              • 12. Re: Change VM IP Address
                                donvito213 Novice

                                 

                                Hi Robert,

                                 

                                 

                                I did check to ensure the VM has its network interface "connected" with the checkmark next to it. Also, I made sure the MAC address for eth0 was specified in the ifcfg-eth0 file as well but that did not work. I will check out the Invoke-VMScript. Thanks

                                 

                                 

                                • 13. Re: Change VM IP Address
                                  donvito213 Novice

                                   

                                  There was one time I managed to get this working perfectly with a similar command below but now I'm getting a new error about "no such file/directory at /tmp/vmware0 line 31":

                                   

                                   

                                   

                                   

                                   

                                  PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; Get-VM sw5-3 | Ge t-VMGuestNetworkInterface -HostUser root -HostPassword &lt;***&gt; -GuestUser root -GuestPassword &lt;***&gt;| ? {$_.Name -eq "eth0"} | Set-VMGuestNetworkInterface -ip &lt;IPADDR&gt; -netmask &lt;NETMASK&gt; -gateway &lt;GATEWAY&gt;

                                  WARNING: The version of VMware Tools on VM 'sw5-3' is out of date and may cause Copy-VMGuestFile to work improperly.

                                  Get-VMGuestNetworkInterface : 5/5/2010 5:24:16 PM    Get-VMGuestNetworkInterfac e    A1868FB9-91A0-4942-B681-962448833706    Execution of the  script in guest OS on VM 'sw5-3' failed: 'No such file or directory at /tmp/vmware0 line 31. ' At line:1 char:43 + Get-VM sw5-3 | Get-VMGuestNetworkInterface &lt;&lt;&lt;&lt;  -HostUser root -HostPassword &lt;PASSWORD&gt; -GuestUser root -GuestPassword &lt;PASSWORD| ? {$_.Name -eq "eth0"} | Set-VMGuestNetworkInterface -ip &lt;IPADDR&gt; -netmask &lt;NETMASK&gt; -gateway &lt;GATEWAY&gt;     + CategoryInfo          : InvalidData: (sw5-3:VirtualMachineImpl) [Get-VMG    uestNetworkInterface], VimException     + FullyQualifiedErrorId : Client20_RunScriptInGuestHelper_RunScriptFileInG    uest_ScriptError,VMware.VimAutomation.VimAutomation.Commands.GetVmGuestNet   workInterface