Quantcast
Channel: VMware Communities : Discussion List - All Communities
Viewing all articles
Browse latest Browse all 178304

Get-Annotation if vm is not null

$
0
0

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】 

EventTimeUserNameVMApplicantApplicationComputeResourceHostDvsDescription
2020/6/21 23:49vsphere.local\xxVM1Cluster1host1
DVS1Task: 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 :

 

EventTimeUserNameVMApplicantApplicationComputeResourceHostDvsDescription
2020/6/21 23:49vsphere.local\xxVM1YYYapache1Cluster1host1
DVS1Task: Set virtual machine custom value

 

 

 

 

 

 

 

 

 


Viewing all articles
Browse latest Browse all 178304

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>