Hi.
We have a large grouping of VM's that are not always required to be running and would like to find a way to shutdown these particular VM's on a sunday night.
Now anyone know how to find a group of VM's (either via label, project, category etc) and pass a shutdown command. Ideally I would like to do this via PowerShell but I will take anything.
Page 1 / 1
There are a number of ways of listing the VMs and then filtering for the 'group' you want but this will be dependent on your naming convention.
To shutdown a VM you have multiple options as well:
Windows:
DOS Cmd:
PowerShell:
Linux:
So all you would have to do was loop thru the above with the filtered computer list.
To shutdown a VM you have multiple options as well:
Windows:
DOS Cmd:
code:
Shutdown / /m \\{computer} {options}
PowerShell:
code:
Stop-Computer –computer {ComputerName} –Credential {AccountID}
Linux:
code:
ssh -t {user}@{ComputerIP} 'sudo shutdown -h now'
So all you would have to do was loop thru the above with the filtered computer list.
Thanks Roberteo.
I'm looking for something in AHV. That way the grouping can be dynamic and we don't have to maintain a listing of VM's that I would have to iterate through.
I have found that in Prism we can group machines with Categories. We can interrogate the categories via REST API and then shut them down... I just now need to learn about REST API's and how to interrogate them 🙂
I'm looking for something in AHV. That way the grouping can be dynamic and we don't have to maintain a listing of VM's that I would have to iterate through.
I have found that in Prism we can group machines with Categories. We can interrogate the categories via REST API and then shut them down... I just now need to learn about REST API's and how to interrogate them 🙂
Could you use the REST API
to get the raw list of VMs and then pipe the results thru a filtered grep then pipe the results of that to the LINUX command above?
Let us know how you make out.
code:
Get vms
to get the raw list of VMs and then pipe the results thru a filtered grep then pipe the results of that to the LINUX command above?
Let us know how you make out.
Also check out this from Steve (aka The Dude):
I know it relates to restoring the VMs in a PD but the code has some omph.
code:
http://stevenpoitras.com/
I know it relates to restoring the VMs in a PD but the code has some omph.
How I solved this:
Created a category in Prism, assigned all the VM's that I want to shutdown to the category.
Then I wrote the script below which queries the category via REST API into a hash table. Then using the Nutanix PS cmdlets, I iterate the hash table and power down the VM's.
It now runs via a scheduled task once a week, powering down all non-essential VM's.
https://github.com/leepryor/Nutanix_Powershell/blob/master/Shutdown-Categorized-VMs.ps1
Created a category in Prism, assigned all the VM's that I want to shutdown to the category.
Then I wrote the script below which queries the category via REST API into a hash table. Then using the Nutanix PS cmdlets, I iterate the hash table and power down the VM's.
It now runs via a scheduled task once a week, powering down all non-essential VM's.
https://github.com/leepryor/Nutanix_Powershell/blob/master/Shutdown-Categorized-VMs.ps1
Well done!
Thank you for sharing this with the Community.
Thank you for sharing this with the Community.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.