We use Hyper-V + SCVMM to host Windows Server 2012 (R2) virtual machines. Currently our deployment procedure includes a lot of PowerShell commands that we have to copy/paste after the VMM template is deployed. For example, some change the NIC names, add a DNS suffix etc.

Is there a way to aggregate these commands into a PowerShell script and let the script run automatically unattended when the VM is booted for the first time? We cannot already set these properties in the template, because for example not all VMs have the same number of NICs.


Have you looked at creating an OnStart scheduled task?

SCHTASKS.EXE /CREATE /F /SC ONSTART /RU Administrator /RP password!!! /TN "First Boot" /RL HIGHEST /TR "Powershell.exe -ExecutionPolicy Bypass -File C:\FirstBoot\FirstBoot.ps1 "

You do need to have a command at the end of the script to remove this task

  • I haven't looked into scheduled tasks yet. Will definitely try this out, thanks! – EsTeGe Feb 7 '16 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.