VMware Cloud Community
GuilhermeAlves
Enthusiast
Enthusiast
Jump to solution

Create custom field on vm Creation

Hi All!

Does anyone know if there is a way to create a custom field in each New VM with the creation info(Date/Time and User)? I was thinking about a trigger in the vCenter but still lost in that...

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

See Alan's post called Running a PowerCLI Scheduled task


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

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Did you already try by setting up an Alarm on the VM creation event ?

From such an alarm you can trigger a script that would do the creation of the custom attribute.


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

GuilhermeAlves
Enthusiast
Enthusiast
Jump to solution

Thanks Luc. The proposite of what i wanted a script or something were to restrict the creation of VMs in some clusters... Even known about the alarms i wanted to create an identification to the VMs, cause we have various VCenters and after a VCenter Migration we lose the creation info of the Vm.

Now, we have na email if someone move or create a VM in wrong places.

In really i didn't see yet if i can create the creation info of The VM in a Custom Field.. I'll try and post here. 😃

0 Kudos
LucD
Leadership
Leadership
Jump to solution

This might help for setting up the alarm  More Fun with vSphere Alarms Contents - VMware Communities


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

GuilhermeAlves
Enthusiast
Enthusiast
Jump to solution


Nice! I can create a custom .cmd script appointing to a .ps1 and change the custom attribs that i need still using powercli. There is some other way to?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could a step in each script that creates a VM, but then you will not be able to take action when a VM is created via the vSphere or Web Client.

An alternative is to run a scheduled script daily, check the events from the last 24 hours and create a Custom Attribute on the new VMs.

You can use the timestamp from the event in that case.


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

0 Kudos
GuilhermeAlves
Enthusiast
Enthusiast
Jump to solution


That's fine to me. I've already did a script to check the alarms daily.. So i'll filter the creations and execute a script to change the custom attribs.

By the way, im using this function (credits for http://wannemacher.us😞

Function Get-TriggeredAlarms {

param (

  $vCenter = $(throw "A vCenter must be specified."),

)

$vc = Connect-VIServer $vCenter -WarningAction SilentlyContinue

 

if (!$vc) {

  Write-Host "Failure connecting to the vCenter $vCenter."

  exit

}

$rootFolder = Get-Folder -Server $vc "Datacenters"

foreach ($ta in $rootFolder.ExtensionData.TriggeredAlarmState) {

   

     $alarm = "" | Select-Object VC, EntityType, Alarm, Entity, Status, Time, Acknowledged, AckBy, AckTime

  $alarm.VC = $vCenter

  $alarm.Alarm = (Get-View -Server $vc $ta.Alarm).Info.Name

   $entity = Get-View -Server $vc $ta.Entity

  $alarm.Entity = $entity.Name

  $alarm.EntityType = $entity.GetType().Name

  $alarm.Status = $ta.OverallStatus

  $alarm.Time = $ta.Time

  $alarm.Acknowledged = $ta.Acknowledged

  $alarm.AckBy = $ta.AcknowledgedByUser

  $alarm.AckTime = $ta.AcknowledgedTime

        if(($alarm.Alarm -ne "Virtual machine cpu usage") -and ($alarm.Alarm -ne "Virtual machine memory usage")){

        $alarm

        }

    }

Disconnect-VIServer $vCenter -Confirm:$false

}

0 Kudos
GuilhermeAlves
Enthusiast
Enthusiast
Jump to solution

My curious Luc, if I wanted to create that schedule task. How would be the script?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

See Alan's post called Running a PowerCLI Scheduled task


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

0 Kudos
GuilhermeAlves
Enthusiast
Enthusiast
Jump to solution

Thats what i thought. Thanks again luc

--- Mensagem Original ---

De: "LucD" <communities-emailer@vmware.com>

Enviado: 19 de fevereiro de 2014 09:38

Para: "GuilhermeAlves" <guilhermestela@hotmail.com>

Assunto: New message: "Create custom field on vm Creation"

VMware Communities<https://communities.vmware.com/index.jspa>

Create custom field on vm Creation

created by LucD<https://communities.vmware.com/people/LucD> in VMware vSphere™ PowerCLI - View the full discussion<https://communities.vmware.com/message/2347602#2347602>

0 Kudos