Off Campus

Michael Greene

Blogs

Add PowerShell to the Hyper-V Server Menu Items

  • Comments 1
  • Likes

Since Hyper-V Server has a reduced footprint, PowerShell is not enabled by default and so it would not make sense to have PowerShell listed by default on the Hyper-V Server Configuration menu.  For those who live by PowerShell and love the simplicity of Hyper-V Server, it is “handy as a pocket on a shirt” (credit: Bill Dance) to add a link on the menu to launch a PowerShell console for local administration.  I would assume that modifying the console is not supported and hereby make the recommendation that if you are going to be so bold, you do so at your own risk and of course should never impact the supportability of your production servers.  That said, check this out!

image

Notes:

Two things I’m not going to include because they are well documented elsewhere.  Number one, you need to enable PowerShell on your server using ocsetup.  You can use oclist to verify whether it is already enabled and/or get the component name.  Number two, the console in Hyper-V server is launched by the Run key under HKLM.  First the %SystemRoot%\System32\sconfig.cmd file is launched to setup the environment, and from there %SystemRoot%\System32\<language>\sconfig.vbs is called to provide the menu.  By default, you will not have access to change either of these files even as a local administrator.  This gives you two choices, you could use takeown and icacls to modify permissions and write your changes to the original file names after making backups, or you could save your changes to new file names and modify the registry key to point to the new .cmd file.  Your choice.

I’m going to assume you have those taken care of and only show what needs to be changed in the .vbs file.  I’m also only demonstrating this as it would occur in a default sconfig.vbs file.  If you have made other changes, your Msg# and case # values may vary, so pay attention.

Step by step:

Look for the list of “const” in the beginning of the file and paste to the bottom:
const L_Msg186_Text    = ") Launch PowerShell"

Find:
wscript.echo cstr(13+offset) & L_Msg018_Text ' Exit to cmd line
Replace it with these two lines:
wscript.echo cstr(13+offset) & L_Msg186_Text ' Launch PowerShell
wscript.echo cstr(14+offset) & L_Msg018_Text ' Exit to cmd line

Find:
                Case "15"
                                if HVS_SKU then              'Exit to command line
                                                wscript.quit
                                end if
Replace it with these two blocks:
                Case "15"
                                if HVS_SKU then              'Exit to PowerShell
                                                oShell.Run "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe",1
                                end if

                Case "16"
                                if HVS_SKU then              'Exit to command line
                                                wscript.quit
                                end if

Disclaimer

Just in case you didn’t catch it above – you modify any files or registry keys at your own risk!  I am certain this would not be supported.

Comments
  • will this work for 2012 R2 ?

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment