0

I use a powershell script, triggered by teamcity, to spin up new Windows Server VMs. Currently, when the machine is up and running, I need to log in via the VMM console to make a couple of configuration changes (enable file sharing, network discovery, msdeploy and remoting over winrm) in order to allow other teamcity jobs to be able to deploy enterprise apps to the VM.

I haven't found any way to run my config setup scripts on the new VM other than by using the GUI console in VMM. For VMHosts, there is Invoke-SCScriptCommand, but this doesn't work for virtual machines themselves. Am I missing something or do I have to alter the template that my VM's are built from, in order to get the required config on the VMs?

grenade
  • 31,451
  • 23
  • 97
  • 126
  • Note that a Hyper-V script that resembles the Invoke-VMScript cmdlet in VMWare is under development (not still released). See [this short video](https://youtu.be/4BMR3J805E8) for details. Edit: As Matt expected, the video is no more online. Sorry. – Pyjo Apr 11 '15 at 12:56

1 Answers1

0

One way you could achieve what you require is by putting all your config changes in a powershell script sitting inside VM template and adding it to VM's startup scripts. The script's first step is checks whether the config changes have been applied in the past by checking some kind of a flag(ie. a file c:\deployed.flag) and last step is to create the flag.

if(Test-Path c:\deployed.flag){
    ## deployment script run already, do nothing
}
else{
    ## your config changing code block
    New-Item c:\deployed.flag -Type f
}

In VMWare/PowerCLI you can run Invoke-VMScript which executes command directly on a VM via VMWare tools but alas Hyper-V Integration Services don't have such functionality.

Raf
  • 9,681
  • 1
  • 29
  • 41