Hi all,
Using the vSphere client, I can add a new VM by providing "Cluster", "ResourcePool", "Datastore" and "Location.".
However, with PowerCLI it requires me to provide "VMHost", which I do not have permission to access.
Is there any way to create a VM when I'm only given the cluster instead of a specific VM host?
The problem you're seeing is due to the implementation of the New-VM cmdlet.
The developers made the VMHost parameter mandatory, which is in fact not required.
If you look at the underlying CreateVM_Task method, you will see that it says there "For a stand-alone host or a cluster with DRS, host can be omitted, and the system selects a default."
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can try something like:
New-VM -VMHost (Get-Cluster "MyCluster" | Get-VMHost | Get-Random) ...
Regards, Robert
Changed the example to use Get-Random instead of Select-Object -First 1.
Message was edited by: RvdNieuwendijk
If you're missing the 'Create Virtual Machine' privilege I don't think Robert's trick will work.
Could you perhaps tell us which message you get when you try to create a VM on a host ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Thanks a lot for your suggestion. I tried (Get-Cluster "MyCluster" | Get-VMHost), but it also failed to work, I think it's because if I don't have permission to see any VMHost, then I won't be able to see any VMHost under MyCluster.
My account has the priviledge to create a VM, so the problem is that using PowerCLI, I cannot create VM if I cannot specify a VMHost. This is not the case for using VI Client as I only need to select a Cluster.
The problem you're seeing is due to the implementation of the New-VM cmdlet.
The developers made the VMHost parameter mandatory, which is in fact not required.
If you look at the underlying CreateVM_Task method, you will see that it says there "For a stand-alone host or a cluster with DRS, host can be omitted, and the system selects a default."
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the info, I guess it means it won't be possible with current New-VM implementation.
I'm afraid not.
Perhaps a hint for the developers for the next PowerCLI build 😉
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference