VMware Cloud Community
rophy
Contributor
Contributor
Jump to solution

How to New-VM without Get-VMHost permission

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?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
6 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
rophy
Contributor
Contributor
Jump to solution

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.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
rophy
Contributor
Contributor
Jump to solution

Thanks for the info, I guess it means it won't be possible with current New-VM implementation.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid not.

Perhaps a hint for the developers for the next PowerCLI build 😉


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos