VMware {code} Community
ePoy
Enthusiast
Enthusiast

get-task with initiator

I have the scriot:

get-task | select -last 10 | select Description, `

                                   @{N='Target';E={$_.ExtensionData.Info.EntityName}}, `

                                   @{N='Status';E={$_.State}}, `

                                   @{N='Percent';E={$_.PercentComplete}}, `

                                   @{N='vCenter';E={$_.ServerId.split('@')[1].split(':')[0]}}, `

                                   @{N='Start Time';E={$_.StartTime}}, `

                                   @{N='Completed Time';E={$_.FinishTime}}, `

                                   @{N='Requested Start Time';E={$_.ExtensionData.Info.QueueTime}} | `

                                   sort 'Start Time' | `

                                   ft -auto

What is the parameter so I can see which user started the task?

Tags (1)
0 Kudos
3 Replies
vijayrana968
Virtuoso
Virtuoso

This should work like this :

get-task | select -last 10 | select Description, ` 

                                   @{N='Target';E={$_.ExtensionData.Info.EntityName}}, ` 

                                   @{N='Status';E={$_.State}}, ` 

                                   @{N='User';E={$_.Uid.split('\')[1].split(':')[0]}}, `

                                   @{N='Percent';E={$_.PercentComplete}}, ` 

                                   @{N='vCenter';E={$_.ServerId.split('@')[1].split(':')[0]}}, ` 

                                   @{N='Start Time';E={$_.StartTime}}, ` 

                                   @{N='Completed Time';E={$_.FinishTime}}, ` 

                                   @{N='Requested Start Time';E={$_.ExtensionData.Info.QueueTime}} | `  

                                   sort 'Start Time' | ` 

0 Kudos
ePoy
Enthusiast
Enthusiast

@{N='User';E={$_.Uid.split('\')[1].split(':')[0]}}, dont work

the particular command returns the user running powercli and not the user who requested execution of the task in vcenter.
Example: This quoted command will always return my user (poyato) when a creation of a vm would actually be another user who started (John)

Description          : Reconfigure virtual machine

Target               : machine1

Status               : Success

User                 : poyato@172.1.1.1 - The one who executed the command, in fact, was John

Percent              : 100

vCenter              : 172.1.1.1

Start Time           : 20/04/2018 12:48:55

Completed Time       : 20/04/2018 12:48:57

Requested Start Time : 20/04/2018 15:48:55

Description          : Reconfigure virtual machine

Target               : machine2

Status               : Success

User                 : poyato@172.1.1.1 - The one who executed the command, in fact, was Mary

Percent              : 100

vCenter              : 172.1.1.1

Start Time           : 20/04/2018 12:48:55

Completed Time       : 20/04/2018 12:48:57

Requested Start Time : 20/04/2018 15:48:55

Description          : Reconfigure virtual machine

Target               : machine3

Status               : Success

User                 : poyato@172.1.1.1 - The one who executed the command, in fact, was Mike

Percent              : 100

vCenter              : 172.1.1.1

Start Time           : 20/04/2018 12:48:55

Completed Time       : 20/04/2018 12:48:57

Requested Start Time : 20/04/2018 15:48:55

In I thought of using the get-vievent command but I noticed that the return to the Creating Machine command also does not return the user (John) who requested the create of vm dxl1tst00002:

PS C:\Users\poyato> get-vm dxl1tst00002 |get-vievent | Where-Object {$_.FullFormattedMessage -imatch "Creating"}

ConfigSpec           : VMware.Vim.VirtualMachineConfigSpec

Template             : False

Key                  : 25430754

ChainId              : 25430753

CreatedTime          : 19/04/2018 14:35:18

UserName             : VSPHERE.XX\vpxd-extension-3d49f847-ec84-473e-9ffe-99d485c9625e

Datacenter           : VMware.Vim.DatacenterEventArgument

ComputeResource      : VMware.Vim.ComputeResourceEventArgument

Host                 : VMware.Vim.HostEventArgument

Vm                   : VMware.Vim.VmEventArgument

Ds                   :

Net                  :

Dvs                  :

FullFormattedMessage : Creating dxl1tst00002 on host px64vibm111.domain.com in Laboratory

ChangeTag            :

0 Kudos
jeffer21
Contributor
Contributor

Hi ePoy,

This might be too late, but you can try this.

get-task | select -last 10 | select Description,

@{N='Target';E={$_.ExtensionData.Info.EntityName}}, 

@{N='Status';E={$_.State}},

@{N='Initiator';E={$_.ExtensionData.Info.Reason.UserName}},

@{N='Percent';E={$_.PercentComplete}},

@{N='vCenter';E={$_.ServerId.split('@')[1].split(':')[0]}},

@{N='Start Time';E={$_.StartTime}}, @{N='Completed Time';E={$_.FinishTime}},

@{N='Requested Start Time';E={$_.ExtensionData.Info.QueueTime}} | sort 'Start Time' | ft -auto