VMware Cloud Community
neibaf89
Contributor
Contributor

Start and stop Vm with customAttribue and Value

I want to create a script that turns my virtual machines on and off with a start date and an end date.


I thought of doing this by assigning custom attributes and value.


If you have any other idea?


I am a beginner in scripting. For now I just managed to make lists of my VMs and the one of which I chose an attribut

get-module  -ListAvailable -name VMware* | Import-Module

Connect-Viserver x.x.x.x -Credential (Import-clixml 'C:\x\x\x.clixml')

$VMsrecette = Get-Cluster "RCT"|Get-VM | select "Name", "PowerState" | Export-Csv c:\x\x\"Liste_des_vm_recettes_$(Get-Date -Format 'yyyy-MM-dd_hh').csv"

$VMsvalueoff = @(Get-Cluster "RCT"|Get-VM|Get-Annotation -CustomAttribute "schedule_poweredOFF" | Where {$_.Value -eq "off"})  | select "AnnotatedEntity","Name","Value" | Export-Csv c:\x\x\"Liste_des_vm_recettes_à-eteindre_$(Get-Date -Format 'yyyy-MM-dd_hh').csv"

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership

The idea is feasible, but how do you intend to run the scripts that checks the Custom Attribute and powers on/off your VMs?
You will probably have to schedule that somewhere?


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

Reply
0 Kudos
neibaf89
Contributor
Contributor

Maybe by creating a .txt.

In the .txt I will be able to write the names of the virtual machines with the start and end date.

If the virutelles machines have the custom value the value is executed

Reply
0 Kudos
LucD
Leadership
Leadership

That's not what I mean.
Which script, and where will it run, is going to check the VMs and eventually take action (power on/off)?
Will it be checking constantly, or once every day?


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

Reply
0 Kudos
neibaf89
Contributor
Contributor

The script will be started from the vcenter.

It must check the status of the On / Off virtual machines as loops at all times to be able to shut down or shut down as needed

Reply
0 Kudos
LucD
Leadership
Leadership

Is that a Windows based vCenter or a VCSA?
Which scheduler do you intend to use for launching the script?


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

Reply
0 Kudos
neibaf89
Contributor
Contributor

Is it a VCSA?
the task scheduler integrates with vsphere client.

Reply
0 Kudos
LucD
Leadership
Leadership

Not sure I understand what you mean there.

In any case, if it is a VCSA  you should not run scripts on there.
Let alone install additional SW on there.


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

Reply
0 Kudos