Automate VM Configuration with SetupComplete.cmd
Your company has an Azure Active Directory (Azure AD) tenant that is configured for hybrid coexistence with the on-premises Active Directory domain. The on-premise virtual environment consists of virtual machines (VMs) running on Windows Server 2012 R2 Hyper-V host servers. You have created some PowerShell scripts to automate the configuration of newly created VMs. You plan to create several new VMs. You need a solution that ensures the scripts are run on the new VMs. Which of the following is the best solution?
Community Insight
This question tests the appropriate method for running automation scripts on newly provisioned VMs, where the common trap is choosing Group Policy startup scripts, which require prior domain join and run on every boot.
When provisioning new Windows virtual machines, running automation scripts requires a mechanism that executes early in the setup process. This page establishes that using SetupComplete.cmd is the best method to ensure scripts run on newly created VMs before domain join and user logon.
Choosing C (GPO startup scripts) is incorrect because startup scripts run on every boot and require the VM to already be domain-joined, whereas newly created VMs need one-time execution before the domain join process.
Community Discussion (98 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
SetupComplete.cmd is specifically designed to execute scripts after Windows Setup completes but before the user logon screen appears. This makes it the ideal mechanism for one-time automation tasks during the initial provisioning of a new VM. It runs before the VM joins the domain, ensuring configuration scripts are applied reliably at creation time without relying on Active Directory connectivity.Why the Other Options Are Wrong
Group Policy startup scripts (Option C) and logon scripts (Option B) require the VM to be domain-joined and GPOs to be applied, which cannot be guaranteed on a newly created VM during its first boot. Furthermore, startup scripts execute on every boot, not just once during initial provisioning. Placing scripts in a VHD (Option D) merely stores them on a disk and does not trigger their execution automatically.Community Comment Notes
Commenters emphasized that "SetupComplete.cmd executes before VM join the" domain, making GPOs unreliable for initial configuration. Another user noted that keeping configuration in a startup script means "the configuration will be executed every time the VM is started", which is inefficient for one-time setup tasks. Others highlighted that just placing a script in a VHD doesn't make it run on boot.Official Reference
Exam Strategy
For VM provisioning questions, distinguish between one-time setup tasks and persistent configuration. Remember that Group Policy requires domain join, which typically happens after the initial OS setup phase, making SetupComplete.cmd the correct choice for first-boot automation.
Related Analysis
Practice All AZ-104 Questions
Access 100 questions with complete answers and detailed explanations.
View Full AZ-104 Practice Test →