Hi,
Being puzzled by "get-annotation", I don't know how to use this function correctly.
Now, I'm trying to write scripts that I wanna get users events , and get the custom attribute of vm if have. But "get-annotation" can not return anything
This is my unfinished scripts
$events = Get-VIEvent -MaxSamples 200 -Start 6/19/2020 -Finish 6/22/2020
$eventCollection =@()
foreach($event in $events){
#exclude "null" user
if( $event.UserName -match "vsphere*"){
$csvline = "" | Select EventTime,UserName,VM,Applicant,Application,ComputeResource,Host,Dvs,Description
$csvline.EventTime = $event.CreatedTime
$csvline.UserName = $event.UserName
$csvline.VM = $event.VM.Name
#### confusion ### This !!! #####
if($csvline.VM.Name -ne $null ){
$csvline.Applicant = Get-Vm $event.VM.Name | get-Annotation -CustomAttribute "Applicant" |select -ExpandProperty value
$csvline.Application= Get-Vm $event.VM.Name | get-Annotation -CustomAttribute "Application" |select -ExpandProperty value
}
#####
$csvline.ComputeResource = $event.ComputeResource.Name
$csvline.Host = $event.Host.Name
$csvline.Dvs = $event.Dvs.Name
$csvline.Description = $event.FullFormattedMessage
$eventCollection += $csvline
}
}
$eventCollection | Export-Csv E:\test.csv -NoTypeInformation -Encoding UTF8
Now : 【Applicant and Application are null --------how to apply it】
EventTime | UserName | VM | Applicant | Application | ComputeResource | Host | Dvs | Description |
---|---|---|---|---|---|---|---|---|
2020/6/21 23:49 | vsphere.local\xx | VM1 | Cluster1 | host1 | DVS1 | Task: Set virtual machine custom value |
【get-vm | get-Annotation -CustomAttribute "Application" |select -ExpandProperty value】
:
flannel-test_01
flannel-test_03
flannel-test_02
Expect input :
EventTime | UserName | VM | Applicant | Application | ComputeResource | Host | Dvs | Description |
---|---|---|---|---|---|---|---|---|
2020/6/21 23:49 | vsphere.local\xx | VM1 | YYY | apache1 | Cluster1 | host1 | DVS1 | Task: Set virtual machine custom value |