Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

When I locally log in to a Server 2012 Core installation, every time I have to type powershell to get to a PowerShell command line instead of plain ol' cmd.

Assuming that I will never remove the PowerShell Windows Feature, how can I configure the server to just get me straight into a PowerShell prompt instead of cmd?

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

Simply add your powershell command line as a new value to the "AvailableShells" regkey to have it as a machine-wide setting:

reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AlternateShells\AvailableShells" /v "90000" /t REG_SZ /d "%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\Powershell.exe"

Reference: http://andrewmorgan.ie/2012/03/30/changing-the-default-shell-of-windows-server-8-core/

Edit: note that the default registry permissions for the "AvailableShells" key will not allow for the change. You will have to change the permissions beforehand (e.g. manually through "regedit") to allow your account (or the "Administrators" group) to perform this change.

share|improve this answer
2  
That looks promising, but it doesn't appear that the Administrators group has write access to that AvailableShells key, only TrustedInstaller does. I can't change permissions without taking ownership of the key. Do you think taking ownership of a system key will present any problems? Here are the ACLs of my registry: gist.github.com/vcsjones/4dca25f94bfb1cfd5857 –  vcsjones May 23 at 20:19
 
OK, well I decided to snapshot the VM and try anyway, it appears to work. The only other thing is the value should be 90000, not 9000. If the value is too low then cmd kicks in first. –  vcsjones May 23 at 20:25
 
@vcsjones it should not present any problems as long as you let TrustedInstaller keep FullControl over the key. To be on the safe side, you could just reset the ownership back to TrustedInstaller after you're done. Oh and thank you for the correction of the number - indeed I have mistyped it in my reg add example. –  syneticon-dj May 23 at 23:04
2  
Or deploy this via a Group Policy for added automation win and circumvent the need to modify any permissions ;) –  Ashley Steel Jun 4 at 23:49
 
I just tried this again, does not work. Access Denied. -1 –  Peter Hahndorf Oct 25 at 12:55
add comment

The command in syneticon-dj's answer does not work, because a normal elevated administrator does not have write access to the key. The comments mention that you need to change the permissions. But this involves a lot of clicking in regedit.exe and does not work for scripted installations.

I use the following PowerShell script:

 $definition = @"
 using System;
 using System.Runtime.InteropServices;
 namespace Win32Api
 {
    public class NtDll
    {
       [DllImport("ntdll.dll", EntryPoint="RtlAdjustPrivilege")]
       public static extern int RtlAdjustPrivilege(ulong Privilege, bool Enable, bool CurrentThread, ref bool Enabled);
    }
 }
 "@

 Add-Type -TypeDefinition $definition -PassThru  | out-null

 $bEnabled = $false

 # Enable SeTakeOwnershipPrivilege
 $res = [Win32Api.NtDll]::RtlAdjustPrivilege(9, $true, $false, [ref]$bEnabled)

 $key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AlternateShells\AvailableShells", [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::takeownership)
 $acl = $key.GetAccessControl()
 $acl.SetOwner([System.Security.Principal.NTAccount]"Administrators")
 $key.SetAccessControl($acl)

 $rule = New-Object System.Security.AccessControl.RegistryAccessRule ("BUILTIN\Administrators","FullControl","Allow")
 $acl.SetAccessRule($rule)
 $key.SetAccessControl($acl)

 New-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AlternateShells\AvailableShells" -name 90000 -value "%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\Powershell.exe" -propertyType String

it first changes the permissions on the key and then sets PowerShell as the shell.

Notice this may only work on an English OS, as it refers to the 'Administrators' group.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.