Search

MachPanel Knowledgebase

HOW TO:Creating Scheduled Task for Windows OS Initialization and Modification

Mudesira Munir
MachPanel

Summary

This article provide a summary on how to Create Scheduled Task for OS Initialization and Modification via Config.bat .

Applies To
This article applies to MachPanel v6.5.25 and above
Steps to create a Scheduled Task
In order to set passwords of VM, we need to create a "Scheduled Task" in sealed image of guest OS:
  1. Open Task Scheduler.
  2. Click the "Task Scheduler Library"
  3. Click "Create Task" by right clicking "Task Scheduler Library" or from "Actions" menu on the right.
    • Name task as: Reset VM Admin Password (Do not remove or disable, required to reset VM from Host)
    • Set task to be run under System user (NT AUTHORITY\SYSTEM).
    • Choose "Run whether user is logged on or not."
  1. Un-check “Do not store password”

3. Under Triggers add new trigger and set “At Start up” and Enabled.

4. Click on "Actions" tab and hit new.

    There is a difference between creation of scheduled task for Gen1 and Gen2 type virtual Machines as explained below:

  • Scheduled Task for Gen1: For Gen1, Set Action to run Powershell.exe -executionpolicy bypass -command ". cd 'a:';  (Get-content 'A:\Config.bat') | Foreach-Object {$_ -replace 'Administrator', 'Administrador'} | Set-Content 'A:\Config.bat'; A:\Config.bat;"”.
    • Action: Start a program
    • Program/Script: Powershell.exe
    • Add arguments (Optional): -executionpolicy bypass -command ". cd 'a:';  (Get-content 'A:\Config.bat') | Foreach-Object {$_ -replace 'Administrator', 'Administrador'} | Set-Content 'A:\Config.bat'; A:\Config.bat;"
  • Scheduled Task for Gen2: For Gen2, Set Action to run “Powershell.exe -executionpolicy bypass -command ". cd 'c:';  (Get-content 'C:\Config.bat') | Foreach-Object {$_ -replace 'Administrator', 'Administrador'} | Set-Content 'C:\Config.bat'; C:\Config.bat;"”.
    • Action: Start a program
    • Program/Script: Powershell.exe
    • Add arguments (Optional): -executionpolicy bypass -command ". cd 'c:';  (Get-content 'C:\Config.bat') | Foreach-Object {$_ -replace 'Administrator', 'Administrador'} | Set-Content 'C:\Config.bat'; C:\Config.bat;"

It is noted that some languages have different Default User name, like for Spanish VMs it is not “Administrator” and it is “Administrador”.

For this, the action we have added in our sealed image schedule task contains argument where you need to replace “Administrador” to your default “UserName”.

  • Critical Note: In above command you have to replace ‘Administrador’ with username in your environment:
    • Example: if it is ‘Administrator’ for your environment, replace ‘Administrador’ with ‘Administrator
    • If it is ‘SuperAdmin’, replace ‘Administrador’ with ‘SuperAdmin’.​
  • Note 2: You do not need to have a Config.bat file on C:\ or A:\ drive, just refer to A:\Config.bat or C:\Config.bat for Gen1 and Gen2 respectively while scheduling a task as shown in above image. Control Panel will automatically create this file in its respective location during VM Provisioning Process.

5. Set Conditions as indicated below:

6. Set Settings as indicated below:

More Information

Please review KB SOP for preparation of Sealed Images for Hyper-V before adding sealed images.

http://kb.machsol.com/Downloads/Download/50314


Details
Type: HOW TO
Level: Intermediate
Last Modified: 2 Years Ago
Last Modified By: zohaib.shaikh
Rated 3 stars based on 3 votes.
Article has been viewed 25K times.
Options
Also In This Category
Tags