Automation

 View Only
  • 1.  how to use powercli Data Objects

    Posted Feb 02, 2017 07:47 AM

    Hi Team,

    Can some one help me how to use any Data Objects for example (Data Object - EventFilterSpec) link https://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.event.EventFilterSpec.html

    people are using them New-Object VMware.Vim.EventFilterSpec but i am confused how to use them in my, how we can know to use specific data object ? thank you in advance.



  • 2.  RE: how to use powercli Data Objects

    Posted Feb 02, 2017 08:09 AM

    It would be handier if you had a real use case.

    But I'll give it a try.

    Assume you want to perform a task that is not covered by a PowerCLI cmdlet, then you could try to use one the vSphere API methods.

    You always start in the API Reference.

    In this case you want to create an EventCollector (to retrieve events from the vCenter).

    We start with the EventManager. (how you know to start with that one is based on the SDK Programming Guide, experience, other threads, blog posts...

    In there you see that there is a method named CreateCollectorForEvents.

    Click the link and go to the method documentation.

    We see the method requires a parameter of the type EventFilterSpec.

    Following the link, we see which properties can/need to be filled in.

    To translate this now in PowerShell/PowerCLI code, you end up with something like this.

    Note that this just a skeleton example!

    # The start of everything

    $si = Get-View ServiceInstance

    # Get the EventManager

    $eventMgr = Get-View -Id $si.Content.EventManager

    # Create the filter parameter object

    $filter = New-Object VMware.Vim.EventFilterSpec

    # Enter the property values that you want to use (this is an example)

    $filter.MaxCount = 100

    # Call the method

    $collectorMoRef = $eventMgr.CreateCollectorForEvents($filter)

    # Get the collector

    $collector = Get-View -Id $collectorMoRef



  • 3.  RE: how to use powercli Data Objects
    Best Answer

    Posted Feb 02, 2017 08:24 AM

    Hi LucD,

    Thank you for the quick response i will try to follow the steps provided :smileyhappy: