0

I want to set up a Windows 10 VM on my workstation from an available VHD from Microsoft. I've got a PSH script that will download the VHD and create the VM in Hyper-V. Check.

Before I use the VM, I want to make sure my favorite development applications are installed and some required network and security configurations and applications are installed. The latter, at least, require certain batch and PowerShell scripts to run.

I can mount the VHD and copy the scripts to the VHD for the VM from PowerShell. Check.

When I launch the VM I can manually run the scripts in the VM and they install and configure things, when run with the right administrative privilege. That's OK, but not ideal. I want this to be fully automatic, so when I log into the VM for the first time then the applications and configurations are either already in place or launch automagically in the background and everything is soon in place.

Examples of the customizations to the base image:

  • Install the latest Chrome (install without user input)
  • Install a particular VPN we use, which requires a bunch of PowerShell configuration changes in administrative mode before the installer will work correctly
  • Install WinMerge

I have not worked deeply with automating the configuration of Windows workstations in ages nor with Hyper-V VMs, so I'm not even sure if the approach is to put scripts in a magic startup folder or to set registry keys in the VM or some other VM setup hack that is quite unknown to me.

Any ideas how to pull this off with PowerShell and maybe a little batch?

Tom Willis
  • 101
  • 2
  • 1
    Run the scripts as startup scripts and not in the startup folder. The startup scripts do not need elevated as those run as system. Figure out the PowerShell to download the latest versions of the applications you download from the Internet and PowerShell a download to a folder and then execute with `start-process` to install. If these are msi packages, maybe have to use msiexec from `start-process` but all of this is doable I believe so you may need to dumb down your question and ask one to start to get the concept down, test more once that's clear, and then ask more questions later. – Vomit IT - Chunky Mess Style Nov 26 '20 at 01:41
  • Otherwise, you are asking for Chrome to be installed no user input of the latest version, the VPN and it's configurations to be installed elevated, and WinMerge, etc. If you pick one to start like Chrome and see if it's possible to download to latest version and install from PowerShell command or script, you can then take a stab at installing that after the download from command line and open another question if there is trouble there with that. – Vomit IT - Chunky Mess Style Nov 26 '20 at 01:43
  • I believe the key will be to install these as startup scripts with Task Scheduler or local group policy and have each PowerShell scripted logic have some sort of conditional logic to only run the download and install if something does not exist, etc. like an exe of an application that only exists if it's installed, etc. There's some quick ideas for you that might give you a jump start. – Vomit IT - Chunky Mess Style Nov 26 '20 at 01:45
  • Thanks, @PimpJuiceIT. I will start down the local group policy path. Any favorite link for that track? TIA – Tom Willis Nov 28 '20 at 01:32
  • Here's a good link https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/dn789196(v=ws.11) that applies to Windows 10 `gpedit.msc` if it's available on the Windows 10 machines you have (assume you're not running a home version). "The path is **Computer Configuration\Policies\Windows Settings\Scripts (Startup/Shutdown)**." ... I'd use PowerShell if you can and not batch but if you have to use both you have the option to tell it to run PowwerShell before the batch scripts if needed. It is quite simple to setup startup scripts. – Vomit IT - Chunky Mess Style Nov 28 '20 at 13:06
  • I may be traveling ground already trod by others. Boxstarter https://boxstarter.org/ Box starter follows the GroupPolicy path I was heading down per @FormerlyPimpJuiceIT's lead at https://superuser.com/questions/1325592/programmatically-create-machine-startup-script-in-local-group-policy-script-exe with remote registry manipulation per https://social.technet.microsoft.com/Forums/windowsserver/en-US/8955416b-392b-466c-811f-8c8d37a2f15a/modify-registry-in-an-offline-vhd?forum=winserverhyperv. Will continue to explore on my own and look at Boxstarter soon. – Tom Willis Dec 07 '20 at 04:12

0 Answers0