Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Power Up your R2 Server Core Shell

Posted on January 27, 2010December 7, 2010

I've recently started using the Server Core option for my test servers, especially for things like domain controllers. I can get by with smaller disk and memory requirements. Once you get the server configured, there's very little you have to do that actually requires logging on to the server. Which is good because all you have is a C:\ prompt, which I know makes some people a little uncomfortable. But with Windows Server 2008 R2, there is another option: PowerShell.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

I've started experimenting with Windows PowerShell as my default shell on an R2 Server Core installation. Now when I logon I get a PowerShell window, not a CMD window. I can setup a PowerShell profile and be fully ready to manage my server. Of course there's so much I can do remotely now but for the sake of discussion let's say I have a need to logon to the console. Normally I would get a CMD window. And while I could start PowerShell from the C:\ prompt, if I know I always want PowerShell, why not make it the default?

The change is very easy to do. But because it involves the registry: backup and test thoroughly in a non-production environment. The registry key to change is HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\winlogon. Look for the Shell entry. Here's how you can do it with PowerShell:
[cc lang="PowerShell"]
PS C:\> get-itemproperty "hklm:\software\microsoft\windows nt\currentversion\winlogon" shell

PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion\winlogon
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\software\microsoft\windows nt\currentversion
PSChildName : winlogon
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
shell : cmd.exe /c "cd /d "%USERPROFILE%" & start cmd.exe /k runonce.exe /AlternateShellStartup"
[/cc]
Notice the shell value is essentially a CMD.EXE shell. We can change that value to anything we want. But first, let's save the value in case we ever want to revert back. You could simply export the entire Winlogon key, but I'm going to simply grab the shell value and save it to a file.
[cc lang="PowerShell"]
PS C:\> get-itemproperty "hklm:\software\Microsoft\windows NT\currentversion\winlogon" Shell | select -ExpandProperty Shell | out-file savedshell.txt
[/cc]
If I ever need to restore this value, I would do something like this:

[cc lang="PowerShell"]
PS C:\> $shell=get-content .\savedshell.txt
PS C:\> $shell
cmd.exe /c "cd /d "%USERPROFILE%" & start cmd.exe /k runonce.exe /AlternateShellStartup"
PS C:\> set-itemproperty "hklm:\software\microsoft\windows nt\currentversion\winlogon" shell $shell
[/cc]

But now my shell is set to PowerShell. I logoff and back on and I now have a PowerShell prompt. I can still run commands like the sconfig script and other CMD tools. So far I haven't found any downside to changing the default shell but if you know of any, please let me know.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d