VMware Cloud Community
yanivamrami
Enthusiast
Enthusiast
Jump to solution

How to use PowerOnVM() and PowerOnVM_Task()

Hello everyone,

I have created a VM the following way:

$newVM = New-VM -Name $vmName -Template $templateObject -ResourcePool $r -OSCustomizationSpec $osSpec -Datastore $d -Location $folderObject -DiskStorageFormat $dsFormat
I than run the following to get the .Net object:
$nVM = $newVM | Get-View
Now, I want to power on the VM, using the following:
$nVM.PowerOnVM()
$nVM.PowerOnVM_Task()
Both return an error message:
Cannot find an overload for "PowerOnVM" and the argument count: "0".
At line:1 char:15
+ $nVM.PowerOnVM <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest
1. What am I doing wrong?!
2. How can I get more data on these kind of cmdlets?
Thank you,
Yaniv
Please rate helpful / correct answers. Thank you
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Yaniv,

according to the SDK the PowerOnVM method requires one parameter. You can specify the ManagedObjectReference of a host. Or you can specify $null. In that case the VM is started on the currently associated host.

$nVM.PoweronVM($null)

But why don't you use the Start-VM cmdlet to start the VM?

$newVM | Start-VM

If you use the PowerShell Get-Member cmdlet you can see which methods and properties an object has. E.g.:

$nVM | Get-Member

Regards, Robert

Message was edited by: RvdNieuwendijk Modified the part about the required parameter.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
5 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Yaniv,

according to the SDK the PowerOnVM method requires one parameter. You can specify the ManagedObjectReference of a host. Or you can specify $null. In that case the VM is started on the currently associated host.

$nVM.PoweronVM($null)

But why don't you use the Start-VM cmdlet to start the VM?

$newVM | Start-VM

If you use the PowerShell Get-Member cmdlet you can see which methods and properties an object has. E.g.:

$nVM | Get-Member

Regards, Robert

Message was edited by: RvdNieuwendijk Modified the part about the required parameter.

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

Thank you. The '$nVM.PowerOnVM_Task($null)' worked.

BTW, what is the difference between the two?

Thanks

Please rate helpful / correct answers. Thank you
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Most of the API methods that are made available through PowerCLI come in 2 flavours, the ones ending in _task and the ones that don't.

The ones ending in _task will return immediatly to your script and place a Task object in the pipeline.

The method will execute in the background (asynchronous).

The methods without _task will wait till the actual task is finished.


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

0 Kudos
yanivamrami
Enthusiast
Enthusiast
Jump to solution

Thanks, I got this one...

I meant, what is the difference between $nVM.PowerOnVM() and '$nVM | Start-VM'

Thanks

Please rate helpful / correct answers. Thank you
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Start-VM is a PowerCLI cmdlet, and PowerOnVm_Task is a vSphere API method.

You can't use the same object to call these.

The PowerCLI cmdlet works like this

$newVM = New-VM ....

Start-VM -VM $newVM

and the method like this

$nVM = Get-View $newVM

$nVM.PowerOnVm_Task($null)

or like this

$newVM.ExtensionData.PowerOnVm_Task($null)


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

0 Kudos