For testing I’ve created some Hyper-V machines on my Windows 8.1 laptop. The burden of deploying software to these virtual machine has been resolved by powershell scripts on the virtual machines. The script is just a simple stop-service, copy new assemblies, start service.
But this still forces me to remote desktop/connect to the virtual machine and start the script from there. An extra icon on the taskbar, an extra ALT-TAB, it started to bother me. That is when I get in the zone and make it work.
Virtual machine
To enable remote powershell the winrm service must be runnning. Also the firewall must allow access over port 5985. Both can be done with powershell.
Get-Service winrm | Start-Service Enable-PSRemoting -Force
The firewall rule created allows access from the local subnet. Enough for my (local) Hyper-V machines. You can always remove the subnet limitation and allow all IP addresses. Remember this is a test machine.
Host machine
On my development/host machine the winrm service must be running. To allow access to the virtual machine the connection must be https (requires certificate) or the machine must be added to the TrustedHosts. I go with the latter option, since it’s the quickest solution. Again this can be done with powershell.
Get-Service winrm | Start-Service winrm s winrm/config/client '@{TrustedHosts="remote_computer"}'
Now I can open a session to the virtual machine.
Enter-PSSession -ComputerName remote_computer -Credentials $prompt
No more remote desktop when deploying and testing my development work on hyper-v machines.
References
Enable and Use Remote Commands in Windows PowerShell, microsoft technet magazine tip