VMware Cloud Community
bowulf
Enthusiast
Enthusiast

Get content & Manipulate Virtual Machines

We are having to stop & start a random list of Virtual Machines this weekend. They are not part of any distinct container, so my idea was to read a list of virtual machines and perform a get-vm | stop<start>-vm. I am having problems with my limited scripting ability. Here was my string:

get-content <text-file-name> | get-vm | stop-vm

That did not work. I also tried a get-content with a foreach command, but I believe my syntax was bad. Could someone provide some assistance? Thank you.

Tags (2)
Reply
0 Kudos
2 Replies
admin
Immortal
Immortal

We are having to stop & start a random list of Virtual Machines this weekend. They are not part of any distinct container, so my idea was to read a list of virtual machines and perform a get-vm | stop<start>-vm. I am having problems with my limited scripting ability. Here was my string:

get-content <text-file-name> | get-vm | stop-vm

That did not work. I also tried a get-content with a foreach command, but I believe my syntax was bad. Could someone provide some assistance? Thank you.

You were pretty close, try:

get-content <text-file-name> | foreach { get-vm $_ | stop-vm }

This assumes that each VM name is on a line by itself.

Reply
0 Kudos
bowulf
Enthusiast
Enthusiast

Thank you that was it...

Reply
0 Kudos