Changing the Hyper-V Server login experience

I have been spending some time working with the free version of Hyper-V server recently (available here: https://www.microsoft.com/en-us/server-cloud/hyper-v-server/default.aspx).  It is lots of fun to see just how much you can do with this free software (hint: you can do everything you can with Hyper-V on a full installation of Windows).

However – one thing that I realized quickly was that I did not like the default login experience.  Normally, when you login to a Hyper-V server you will get a command prompt and a running instance of the Server Configuration tool:

hypervserver1

This is all fine and good when you are first setting the server up.  But after then it gets a bit annoying.  The reality is that most of the time you will be managing Hyper-V remotely – from another Windows computer.  The only reason why you would want to login to a Hyper-V server directly is because something has gone wrong, and you need to do some troubleshooting.

Now, when it comes to troubleshooting a Hyper-V server – there are really only two things I want:

  1. I want to know if all of my virtual machines are okay.
  2. I want a PowerShell window so I can use the Hyper-V cmdlets to dig in deeper if I need to.

Having PowerShell launch by default is quite easy.  Just launch PowerShell from the command prompt (type in “PowerShell” and hit enter) and then run this command:

Set-ItemProperty "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\WinLogon" Shell 'PowerShell.exe -WindowStyle maximized'

Now you will get a PowerShell window instead of a command prompt whenever you login.  But I wanted a bit more than that.  To get a better experience – I needed to create a PowerShell profile.  To create the profile I ran these commands:

 Set-ExecutionPolicy RemoteSigned
 New-Item -path $profile -type file -force
 notepad $profile

And put the following information into the profile file:

 # Maximize the window
 (Get-Host).UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(((Get-Host).UI.RawUI.MaxPhysicalWindowSize.Width-3),(Get-Host).UI.RawUI.BufferSize.Height)
 (Get-Host).UI.RawUI.WindowSize = (Get-Host).UI.RawUI.MaxWindowSize
  
 # Get the colors corrected
 (Get-Host).UI.RawUI.ForegroundColor = "White"
 (Get-Host).UI.RawUI.BackgroundColor = "DarkBlue"
  
 # Change path and clear the screen
 cd \
 cls
  
 # Display a welcome message
 write-host Welcome to $env:computername
 write-host
 write-host Current virtual machine status:
 get-vm
 write-host

The result is that when I login to my Hyper-V server now, I am presented with a full screen PowerShell window and a listing of my virtual machines straight away. Very handy. 

hypervserver2

Cheers,

Ben