VMware Cloud Community
mlurette
Contributor
Contributor
Jump to solution

Event and session information

Hey everyone,

I'm a complete noob at powercli and powershell in general. I was wondering if anyone knows of any documentation regarding events and sessions. This isn't very urgent, but for future reference I'd like to know where this information is kept, how to access it, and what exactly I'm accessing. Been playing a lot recently with get-(*xyz*) | get-member and looking at all the different properties and methods. When I read some of the posts on this site I think to myself "wow, how in the world did they know to look there?". Also, some event types have similar the same property names, so how do you specify where to query the information?

So, either everyone on here is a wizard, or there is some documentation out there that everyone is looking at without me. Any help would be much appreciated as it will make me look a little less stupid at work.

Thanks in advance,

Martin

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There are 2 official information sources available, one is the VMware vSphere PowerCLI Overview, it contains the help for all the cmdlets, but also the description of all the properties in the objects returned by the PowerCLI cmdlets.

The second is the VMware vSphere API Reference.

This one contains all the vSphere methods and objects.

How to know which documentation to use?

As always It depends on what you are trying to do.

If the information you are looking for is available through a PowerCLI cmdlet, use the first reference.

If the information is not directly available from or through a PowerCLI cmdlet, in other words you have to use the ExtensionData property and the Get-View cmdlet, use the second reference.

In the PowerCLI Reference, shameless plug :smileygrin:, we have a chapter dedicated to the SDK/API, that goes into much more detail when to go for the 2nd option, and how to do that.


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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

There are 2 official information sources available, one is the VMware vSphere PowerCLI Overview, it contains the help for all the cmdlets, but also the description of all the properties in the objects returned by the PowerCLI cmdlets.

The second is the VMware vSphere API Reference.

This one contains all the vSphere methods and objects.

How to know which documentation to use?

As always It depends on what you are trying to do.

If the information you are looking for is available through a PowerCLI cmdlet, use the first reference.

If the information is not directly available from or through a PowerCLI cmdlet, in other words you have to use the ExtensionData property and the Get-View cmdlet, use the second reference.

In the PowerCLI Reference, shameless plug :smileygrin:, we have a chapter dedicated to the SDK/API, that goes into much more detail when to go for the 2nd option, and how to do that.


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

mlurette
Contributor
Contributor
Jump to solution

Wow, awesome thanks!

The API Reference was exactly what I was looking for. The only thing missing is examples, but that can be replaced by trial and error. This may be a dumb follow-up question, but since there seems to be a lot of duplicate information in some of the managed object types, is there a certain method of getting event/session information that is quicker and more efficient? As I've mentioned before in a different question, I'm trying to write up an automated script to monitor what users are active, and if so, what VM are they using? I plan on having a separate VM on our server to do nothing but run the script, export the list to html and open the page every minute or so. The end goal of the project is to give the developers a "real-time" snap-shot of who is working where to avoid conflicts and keep people happy.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There are examples, not necessarily in PowerCLI, available in the VMware Developer Center.

At least you should be able to see how the API methods and properties are used.

You have a quick access to the latest events via the latestEvent property in the EventManager object.

$si = Get-View ServiceInstance -Server $default:globalviserver

$evtMgr = Get-View -Id $si.Content.eventManager

$evtMgr.latestEvent


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

mlurette
Contributor
Contributor
Jump to solution

Ok, cool thanks.

I guess my follow up question(s) are the following:

I'm getting the latest sessions, and sorting them like so:

$maxtime = new-timespan -minute 60

$si =get-view serviceinstance

$sm = get-view $si.Content.sessionManager

$names = ($sm.sessionlist | where {(new-timespan($_.Lastactivetime).tolocaltime()) -lt $maxtime } | select UserName, FullName, @{N='Idle Time'; E={((new-timespan($_.Lastactivetime).tolocaltime()).totalminutes)}} | Sort-object ("Idle Time"))

... and then I get a list of recent "mks" events to see who has opened a VM, and is theoretically working in it like so:

$now = get-date

$then = $now.addhours(-2)

$events = Get-VIEvent -start $then -finish $now| Where {$_.TicketType -eq "mks" -and $_.Vm.Name -ne ("Who's connected")} | Select UserName, @{N='VM';E={$_.Vm.Name}}, CreatedTime | sort-object CreatedTime

Now I compare the lists using a bunch of nested foreach loops to match what active sessions are using what VM. What I don't get is what qualifies as an "active session"? Also, the mks events only seem to show when the open the console. Is there an event/property to monitor whether or not they are still using it (i.e input to the VM vs. just an open console)?

And again thanks in advance for all your help.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik, there are no events that show if someone is interacting with the console vs just an open console.

You could have a look at the vmware.log that is stored in the VM's folder (by default).

That logs quite some info related to VMware Tools and any interaction with them, but not sure if the info you are looking for is in there.


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

0 Kudos