Automation

 View Only
  • 1.  Using view methods that require parameters

    Posted Aug 22, 2018 11:33 AM

    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...



  • 2.  RE: Using view methods that require parameters

    Posted Aug 22, 2018 12:55 PM

    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)



  • 3.  RE: Using view methods that require parameters

    Posted Aug 22, 2018 12:58 PM

    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?



  • 4.  RE: Using view methods that require parameters
    Best Answer

    Posted Aug 22, 2018 01:25 PM

    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



  • 5.  RE: Using view methods that require parameters

    Posted Aug 22, 2018 01:44 PM

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

    Great to know!