Automation

 View Only
Expand all | Collapse all

New-VM is driving me nuts!

  • 1.  New-VM is driving me nuts!

    Posted May 09, 2008 04:26 AM

    Ok, someone tell me why this is not working? Geez, I hope because it is beta? I have not tripped over a bug... Have a ESX 3.5 Update 1 host. That is it, no VirtualCenter server, keeping things simple. Have a Window XP/sp2 workstation.

    Get-ESX works....

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> Get-ESX -server 192.168.15.90 -user root -password <password>

    Name

    -


    192.168.15.90

    Get-VMhost works...

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> Get-VMhost

    Name State Id

    -


    -


    --

    test.domain.com Connected HostSys...

    But if I try to use New-VM...

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> New-VM -name TEST -host ( Get-VMHost ) -memoryMB 256 -diskMB 1000

    New-VM : Object reference not set to an instance of an object.

    At line:1 char:7

    + New-VM <<<< -name TEST -host ( Get-VMHost ) -memoryMB 256 -diskMB 1000

    Even following the examples in blogs, forums...

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> get-vmhost | new-vm -name "test" -memorymb 256 -diskmb 4000

    New-VM : Object reference not set to an instance of an object.

    At line:1 char:20

    + get-vmhost | new-vm <<<< -name "test" -memorymb 256 -diskmb 4000

    I find a lot of example that SAY they work... but no actual output proving they work, and I know someone has to have go this working, right? HELP!



  • 2.  RE: New-VM is driving me nuts!
    Best Answer

    Posted May 09, 2008 06:28 AM

    Do you have more then 1 ESX server ?

    In that case the cmdlet Get-VMHost returns an array of vmhostimpl objects.

    The New-VM cmdlet expects a vmhostimpl object after the -host parameter.

    Try adding the name of the specific ESX server where you want to create the new VM.

    New-VM -name TEST -host ( Get-VMHost -Name <FQDN-of-the-ESX-server> ) -memoryMB 256 -diskMB 1000
    

    That definitely works in my environment (see screenshot).



  • 3.  RE: New-VM is driving me nuts!

    Posted May 09, 2008 04:52 PM

    Your reply brings up two questions I need to address, 1) I have one desktop, and one ESX host, nothing else. 2) I have no name resolution enabled in this specific setup, that is why I am using just the IP address. Maybe New-VM or Get-VMHost have a name resolution quirk. I will give it another shot and see if I can resolve my problem. I expect it is environmental at this point.



  • 4.  RE: New-VM is driving me nuts!

    Posted May 10, 2008 06:36 PM

    Well... no joy... I setup name resolution... but still get the same issue...

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; $test=get-viserver -server virtual -user root -password autoinstall

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; write-host $test

    VMware.VimAutomation.VIServerImpl

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; $test1=get-vmhost -server $test

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; write-host $test1

    VMware.VimAutomation.Client20.VMHostImpl

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; new-vm -vmhost $test1 -name test

    New-VM : Object reference not set to an instance of an object.

    At line:1 char:7

    + new-vm &lt;&lt;&lt;&lt; -vmhost $test1 -name test

    So... New-VM is still driving me nuts!



  • 5.  RE: New-VM is driving me nuts!

    Posted May 10, 2008 07:04 PM

    I just noticed something odd, my version of New-VM does NOT have "-host" as an option, but only "-VMhost" does this make any sense?

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; help new-vm

    NAME

    New-VM

    SYNOPSIS

    Creates a new virtual machine.

    SYNTAX

    New-VM [[-VMHost] &lt;VMHost&gt;] -Name &lt;String&gt; [-Data

    New-VM [[-VMHost] &lt;VMHost&gt;] -Name &lt;String&gt; [-Data



  • 6.  RE: New-VM is driving me nuts!

    Posted May 12, 2008 07:13 AM

    Those 2 attributes are aliases. Nothing wrong with your installation.

    If you like to see all attributes and their aliases you can run this:

    foreach ($paramset in (Get-Command New-VM).ParameterSets){
      foreach ($param in $paramset.Parameters){
        foreach ($alias in $param.Aliases){
          Write-Host $param.Name $alias
    	}
      }
    }
    



  • 7.  RE: New-VM is driving me nuts!

    Posted May 12, 2008 01:22 PM

    @LucD, you are my hero. I had done this before using an archiaic text parsing method of the cmdlet help which was not all that successful. It was a dirty hack and I just didn't have time to revisit it. Your technique is perfect. I've modified it a little bit to output a custom object rather than text and have posted it on this script repository: http://powershellcentral.com/scripts/249

    Hal Rottenberg

    Co-Host, PowerScripting Podcast (http://powerscripting.net)



  • 8.  RE: New-VM is driving me nuts!

    Posted May 12, 2008 06:40 PM

    Added some more properties and tweaked otherwise. New version is at http://powershellcentral.com/scripts/255.

    Hal Rottenberg

    Co-Host, PowerScripting Podcast (http://powerscripting.net)



  • 9.  RE: New-VM is driving me nuts!

    Posted May 13, 2008 03:34 AM

    Nice trick to be sure for capturing the parameters. But does not solve my problem. -host is not recognized, I can not execute the example LucD already provided, and -VMhost even when know I have a valid VMhost object, New-VM fails still. I can not run the examples in the FAQ either. Some thing is not right still.



  • 10.  RE: New-VM is driving me nuts!

    Posted May 14, 2008 11:56 PM

    Nice trick to be sure for capturing the parameters. But does not solve my problem. -host is not recognized, I can not execute the example LucD already provided, and -VMhost even when know I have a valid VMhost object, New-VM fails still. I can not run the examples in the FAQ either. Some thing is not right still.

    Could you try it slightly differently:

    get-vmhost | new-vm -name newtest

    and see if that works?



  • 11.  RE: New-VM is driving me nuts!

    Posted May 15, 2008 03:52 AM

    Will Do. Or did rather...

    Useful starting points:

    Get-VICommand - returns a list of available VMware Infrastructure commands

    Get-VC or Get-ESX - logs in to a VC or ESX server

    Get-VM - finds available virtual machines

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> get-viserver -server 192.168.15.104 -user root -password autoinstall

    There were one or more problems with the server certificate:

    • A certification chain processed correctly, but terminated in a root certificate which isn't trusted by the trust provider.

    • The certificate's CN name does not match the passed value.

    Name

    -


    192.168.15.104

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> get-vmhost

    Name State Id

    -


    -


    --

    server.dachshund.org Connected HostSys...

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> get-vmhost | new-vm -name test

    New-VM : Object reference not set to an instance of an object.

    At line:1 char:20

    + get-vmhost | new-vm <<<< -name test

    PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows>

    I am starting to think there is something wrong elsewhere in the setup again. I will try this test again with a clean install of the toolkit in a different lab setup.



  • 12.  RE: New-VM is driving me nuts!

    Posted May 17, 2008 07:46 PM

    Well, I did make some progress, I built a 2003 Server (standard 32-bit) R2 SP2, installed VC 2.5 Update1 with VI Client, installed PowerShell, installed VIToolKit Beta 1.0. In this configuration, I was successful with creating a couple of VMs. Everything worked as expected, but I am still testing. I then went back to the Windows XP SP2 box, which has the VI client, PowerShell and VIToolKit Beta 1.0. I still could can not create a VM via VIToolKit as documented above when connecting to an ESX host.

    Validated that the ESX 3.5 Update1 host was current and it was not current to the very latest patches, the most recent 7 or 8 where outstanding, I applied them via UM on VC - by the way - UM is a pain to use when the ESX host keeps disconnecting and stalling the remediation task.

    For whatever reason, now, creating VMs is working on the XP SP2 box either in the VC or ESX direct conntect. Very odd, very weird. I have not as yet deep-dived in the the updates for ESX that were applied, I don't recall any thing documented that said an ESX host has to be fully patched to work with VIToolKit, but then again, still digging.

    VMware, if you have your ears on? This sound like something that is known or not? Maybe VIToolKit should check the patch level of the VC or ESX host when it connects? If that turns out to be the issue?



  • 13.  RE: New-VM is driving me nuts!

    Posted May 19, 2008 01:41 AM

    The patch level is not supposed to make any difference. Do you happen to know which patches you applied? Any details you can give would help us out.



  • 14.  RE: New-VM is driving me nuts!

    Posted May 19, 2008 06:32 PM

    Yeah, I just need to look at the loggig details from UM or ESX host applicable... Server started as ESX 3.5 Update 1... with all patches in a baseline attached, showed 8 out of compliance, I figured it was the last 8 or more recent 8...

    Server build on 050908...

    Not additional patches applied on until 051708...

    20084408-BG

    20084401-BG

    20084402-BG

    20084403-BG

    20084407-BG

    20084404-BG

    20084405-BG

    20084406-BG