IT Pro Resources
Bill Baer on...
Preparing virtual machines for demonstrations can be a tedious process, compounding this is when virtual machines need to be started or shut down in a specific order. For example, starting database servers prior to starting web servers, or starting the preferred active node before the passive node. Starting those machines; however, is only a portion of the process, in most cases you will want them to be “available” before starting a subsequent machine. For example, having an iSCSI Target available before the consuming iSCSI initiators are available. Windows PowerShell, is perfect to support this scenario – it’s something I use almost everyday and have shared an example (below) of how you can accomplish all of these tasks…
So what does it do?
Provides parameters to Start/Shut Down one or more virtual machines.
Checks for process elevation, escapes if the script is not run elevated.
Starts the Hyper-V Virtual Machine Management Service if not running.
Iterates through an array of virtual machines stored in a .txt file.
Starts each virtual machine in the .txt file and waits for the heartbeat status to report ‘OK’ before starting the next virtual machine in the list. Virtual machines are started in the order they appear in the source file, waiting ensures a clean start up – particularly where a defined start order with dependencies exists.
Shuts down virtual machines in the reverse order they were started by reading the source file bottom to top. Waits for the virtual machine heartbeat status to report ‘’ before processing the next virtual machine.
Displays a progress bar to report on the status of the operation.
Using the scripts requires 1) saving the attached script as <name>.ps1 2) creating source .txt file with virtual machines listed in the preferred start up order. For example,
3) Saving the script and source .txt file in the same location.
4) Running the script as <name>.ps1 –Operation Start –Source <name>