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!
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).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
Well... no joy... I setup name resolution... but still get the same issue...
PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> $test=get-viserver -server virtual -user root -password autoinstall
PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> write-host $test
VMware.VimAutomation.VIServerImpl
PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> $test1=get-vmhost -server $test
PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> write-host $test1
VMware.VimAutomation.Client20.VMHostImpl
PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> 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 <<<< -vmhost $test1 -name test
So... New-VM is still driving me nuts!
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> help new-vm
NAME
New-VM
SYNOPSIS
Creates a new virtual machine.
SYNTAX
New-VM [[-VMHost] <VMHost>] -Name <String> [-Data
New-VM [[-VMHost] <VMHost>] -Name <String> [-Data
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 } } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@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)
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)
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.
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?
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.
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?
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.
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