Built a vMware script to switch off and on a vCenter

heze54
heze54 used Ask the Experts™
on
Hi,

I´ve a vCenter with up to 1XX Vmachines listed by templates. All of them (windows, ubuntu,redhat..) have vTools installed 5.1 U2.

I need a script to switch off and after thar, switch on all of them by template

For Example:

template1
template2
..
..
..

How to do this? I don´t have enough knowedge to build a powercli script

any idea?

Regards
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Andrew Hancock (VMware vExpert / EE Fellow)VMware and Virtualization Consultant
Fellow 2018
Expert of the Year 2017

Commented:
Templates cannot be powered on, so what do you want to do with the templates?

Author

Commented:
Hi,

Sorry I meant folders no templates
Andrew Hancock (VMware vExpert / EE Fellow)VMware and Virtualization Consultant
Fellow 2018
Expert of the Year 2017

Commented:
You want to switch on ALL VMs by Folder?

These are Virtual Machines, not templates, as templates cannot be powered on, only deployed and /or  to VMs.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Hi,

Forget my mistake(templates) Iwas talking about folders and inside them, VM running.

Yes, by folder or/and export the whole enviroment (Vmachines) to a cvs file.. for example and then, reorder the file and run the operation
Messaging and Directory Services
Commented:
Try this:

$FolderName="Redhat VMs"

$vms=get-vm -location "$FolderName" | Where-Object {$_.powerstate -eq ‘PoweredOn’}

$vms |select Name | export-csv c:\vms.csv -notypeinformation

$vms | Shutdown-VMGuest -confirm:$false

Author

Commented:
Hi,

I exported the csv  and , how to run a for to eof switching off all machines listed on a csv file?

Author

Commented:
Nice comment for me.

Right post

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial