Provision Window VM instance with powershell script that enables:
- WinRM
- RDP
- SSH*
- rsync*
on OS up from Windows 7 SP1.
Let you want to launch a VM (virtual machine) in a cloud—AWS, Openstack, Auzre, et cetera—with arbitrary image of Windows OS – how do you install software on the VM, configure settings?
When you are going to spawn VM instance in a cloud you have an option to pass cloud-init script in Powershell language (for Windows OS). This script will run only once at the end of VM's creation. Cloud-init leads us to a couple of ways how to achive our goals (install and configure software on VM):
- mega-script that installs and configure all software you need – BAD
- script that downloads and installs any of CM (configuration management) tools—SaltStack, Ansimble, Chef —then just pull/push appropriate configuration from you CM server – NOT BAD
- enable WinRM (à la SSH for Windows) on VM – GOOD – contemporary IaC tools (infrastucture as code), like CloudFormation, Terraform and Vagrant, can execute VM's post-creation tasks: upload files to VM, execute sets of commands on VM, but they need a communication tool—WinRM (service supports execution of Powershell scripts remotely).
- sets VM's network interfaces as Private – Windows very restricts communications on Public interfaces
- enables WinRM over HTTP
- enables execution of .ps1 files on VM
- enables RDP – you may view VM's desktop now
- creates local administrator (LocalAdmin, you can change this) – sometimes it is very hard to figure out automatically the password and correct name of build-in Administrator (may vary depending on localization), that is why we need our own admin. Set your IaC tool to use this credentials.
- (optional) install SSH and rsync—if you wish to opt-in uncomment last strings
- copies your pki public key from the cloud to LocalAdmin's profile
- installs CYGWIN with rsync package
- installs and run OpenSSH