VMware Cloud Community
Srinivas_k
Enthusiast
Enthusiast
Jump to solution

how to use powercli Data Objects

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.

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
Srinivas_k
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

Thank you for the quick response i will try to follow the steps provided Smiley Happy

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

eventMgr.png

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

Click the link and go to the method documentation.

collector.png

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


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

Reply
0 Kudos
Srinivas_k
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

Thank you for the quick response i will try to follow the steps provided Smiley Happy

Reply
0 Kudos