Schedule Tasks in Task Scheduler
With auto start/stop scripts ready, it's time to set up 2 tasks in Task Scheduler to start VMs when the host system is booting up and stop them when the host is shutting down. There are other possible approaches, but using Task Scheduler may be the simplest way on Windows 7 Home Premium.
Task Scheduler can be find in Start Menu -> All Programs -> Accessories -> System Tools. Right click on it and select 'Run as administrator' to run it using the same adminsitrator account you like to run the script. In the left pane of Task Scheduler window, select 'Task Scheduler Library' and right click on it. Select 'New Folder...' to create a folder, e.g. VMware. The 2 tasks will be placed inside that folder. (See PIC-2.)
To create a task for starting VMs, right click on the new folder and select 'Create Basic Task...'. Give it a name and description. Select 'When the computer starts' for Trigger and 'Start a program' for Action. When asked for a Program/script, enter 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' into the entry filed. (Please adjust according to your PowerShell location.) In the Add arguments (optional) field, enter '-File "E:\Scripts\Auto-VMs.ps1" start'. (Replace the script path and name with the one you use.) (See PIC-3.)
At the Summary step, please check the box 'Open the Properties dialog for this task when I click Finish' before click on Finish button. The task's Properties window will show up to continue the configuration. On the Properties window, please check the user account to run the script is correct, then select 'Run whether user is logged on or not' and check the box 'Run with highest privileges'. Also make sure the Configure for selection box has 'Windows 7, Windows Server 2008 R2'. You will need to enter the password of the admisntrator account for running the script after you click on the OK button. (See PIC-4.)
Repeat the same process to create a task for stopping/suspending VMs. But this time, when asked for Trigger, select 'When a specific event is logged'. Then, for Log and Source dropdown lists choose 'System' and 'USER32', respectively. In Event ID field, enter '1074' which is the event logged when a shutdown is initiated. (See PIC-5.)
Again, select 'Start a program' for Action, and when asked for a Program/script, enter 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' into the entry filed (with adjustments according to your PowerShell location). In the Add arguments (optional) field, enter '-File "E:\Scripts\Auto-VMs.ps1" suspend soft'. (Replace the script path and name with the one you use.) You can also use 'suspend hard', 'stop soft' or 'stop hard' as arguments to the script. (See PIC-6.)
Finally do the same thing as before for the Summary page and the subsequent Properties window. Now you have 2 tasks setup to automatically start and stop/suspend virtual machines during the host system's startup and shutdown.