VMware Cloud Community
Oharutz
Contributor
Contributor

Triggering A PS Script After taking a snapshot on a VM

Hello!

The company i am working for uses a scheduled Snapshot Report based on a powercli scripts, it prints all the VMs that has snapshots, shows their age, and creation time.

I am looking for a way to add an indication for the User that started the task - but independently from the task itself, since it may be gone and i won't be able to know who took the snapshot.

A way that i have been thinking about in order to make this information permanent is to add an Annoation to the virtual machines named "Last Backup Taken By".

Afterwards i wrote this short script in Powercli.

$snap = Get-Snapshot (Get-VM) | Sort-Object -Property Created -Descending | select -First 1

$username = Get-VIEvent -Entity $snap.VM -Finish $snap.Created -MaxSamples 1 | select -ExpandProperty UserName

Set-Annotation -Entity $snap.$vm -CustomAttribute "Last Snapshot taken by" -Value $username

Then i moved to the stage of setting the Alarm Definition and integrating this script in it.

Right after it i have tried to find an event ID for this specific purpose, but i couldn't relate it to any event ID.

I have also tried to set a trigger of VM Snapshot Size Below 1 GB but it triggers the Alarm on all of the VMs, althogh the Annoation was written successfully.

I am unsure about setting a trigger of VM Size Above XGB because it may not be effective for snapshots on virtual machines (that will grow only when the vm will start and have active I/Os).

I will be happy to get ideas about implementing it in different ways (including vRO).

Thanks!

0 Kudos
3 Replies
sjesse
Leadership
Leadership

This should be moved the the powercli area.

0 Kudos
Oharutz
Contributor
Contributor

I am not sure.

The problem i mentioned is about the trigger - belongs to vSphere side,

Not the script itself.

0 Kudos
sjesse
Leadership
Leadership

Anything related to scripts should be there, some people who just watch this forum don't do any scripting. Feel free to leave it here, I just think you will get better responses there. You can try to find the event using this scripts here

http://www.lucd.info/2009/10/06/events-a-great-source-of-information-part-1/

and then put that event in the alarm, but I'm not sure thats best, but as you found I think it would trigger for all the vms. Its probably best to write a script that runs every few minutes that checks for the snapshot event, and if so then either sends an email or create an event through powercli.

0 Kudos