Marco_2_G
Contributor
Contributor

Using view methods that require parameters

Jump to solution

Hello everybody

Sorry for being a bother. I expect this to be a pretty dumb question but my google fu is weak today and I just can't find the answer.

I want to create snapshots for a list of VMs. I have them as view objects in a variable. I want to use the createsnapshot_task method and I want to pass it a name for the snapshot. However for the life of me I cannot find any examples on how passing parameters to a method works.

I expect they need to go in the parentheses of $vm.createsnapshot_task() somehow. I have found a list of possible parameters in the API docs but no example on the syntax...

Sorry again...

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

There are 2 ways of finding out.

  1. Use the API Reference, see CreateSnapshot_Task. ​Note that all API methods come in 2 forms
    1. With the _Task suffix: this will call the method and come back immediately (like the RunAsync switch on PowerCLI cmdlets). These calls return a Task object
    2. Without the _Task suffix: this will wait till the method call is finsihed.
  2. Call the method without parenthesis. It will show you the parameters

snap.png


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership

Try like this

$vm = Get-View -ViewType VirtualMachine -Filter @{'Name'='MyVM'}

$snapshotName = 'Test'

$snapshotDescription = 'Test Snapshot'

$memory = $false

$quiesce = $true

$vm.CreateSnapshot($snapshotName,$snapshotDescription,$memory,$quiesce)


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

0 Kudos
Marco_2_G
Contributor
Contributor

Thank you, this solves my immediate problem.

Can you tell me what the best way is to find this out? I expect the parameters all need to be present and in the right order. Where do I see these requirements for each method?

0 Kudos
LucD
Leadership
Leadership

There are 2 ways of finding out.

  1. Use the API Reference, see CreateSnapshot_Task. ​Note that all API methods come in 2 forms
    1. With the _Task suffix: this will call the method and come back immediately (like the RunAsync switch on PowerCLI cmdlets). These calls return a Task object
    2. Without the _Task suffix: this will wait till the method call is finsihed.
  2. Call the method without parenthesis. It will show you the parameters

snap.png


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

0 Kudos
Marco_2_G
Contributor
Contributor

Thank you so much. I never would have even tried it without ().

Great to know!

0 Kudos