Remote powershell or how I manage my local Hyper-V machines

powershellFor 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.
winrm_firewall

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

About erictummers

My work as a recruited developer changes almost every month. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Tooling and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s