I have a bunch of scripts I use when I'm building a lab to install "stuff" (that's the Technical Term we IT Professionals use) that I need to manage and work with a virtual machine. Now, when I build from a SysPrep'd image, that's not an issue, but if I have to build from an ISO, I want to automate the process as much as possible. So I have a couple of Setup scripts I run that install gVim, HyperSnap (my screen capture tool), and various other things.
As I was building a new lab this week, I realized that those scripts were all designed to deal with full GUI installations, and had no provisions for not installing applications that make no sense and can't work when there's only a Server Core installation. So, time to find out how I can tell if I'm running as Server Core, obviously. A bit of poking around, and I came up with the following:
$regKey = "hklm:/software/microsoft/windows nt/currentversion" $Core = (Get-ItemProperty $regKey).InstallationType -eq "Server Core"
(You could do that as a single line, obviously, but I broke it up to make it easier to see on the page. )
The result is stored as a Boolean value in $Core, and I can now branch my installation decisions based on the value of $Core. (Note there ARE other ways to determine whether you're running on Server Core, but they appear to all be programmatic ones not well suited to the avowedly non-programmer IT system administrator types like me. )
Beginning in Windows 8.1, you could set the Windows PowerUser menu (right-click on the Start button, or Win-X key) to show Windows PowerShell and Windows PowerShell (Admin) on the menu instead of Command Prompt and Command Prompt (Admin). But every single new machine you log on to, you had to change that. A nuisance, at least. So, I created a Group Policy Preference to set the registry key for this, and linked this to the Default Domain Policy.
Apparently, Microsoft is finally catching up, and this is going to be the default on Windows 10 beginning with the build that's coming down today. About time!
For those of you who are not on the Fast Ring of Windows Insider builds, the registry key you need to set is:
To set that with Windows PowerShell, use:
Set-ItemProperty HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced ` -Name DontUsePowerShellOnWinX ` -Value 0 ` -Type DWord
You can also use Group Policy Preferences to set that as part of a Group Policy Object (GPO).
- Open the Group Policy Management Console (gpmc.msc)
- Right-click the GPO you want to modify (I chose the Default Domain Policy for my domain)
- Select Edit from the right-click menu to open the Group Policy Editor
- Expand the User Configuration container, then Preferences and select Registry in the left pane.
- Right-click in the Registry details pane and select Registry Item from the New menu:
6. In the New Registry Properties dialog, select Update for the Action, HKEY_CURRENT_USER for the Hive, and a Key Path of \Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced.
7. The Value Name is DontUsePowerShellOnWinX, with a Value Type of REG_DWORD and a Value Data of 0, as shown below.
8. Click OK, and then close GPEdit. The Group Policy will be applied to following the next reboot and logon of each user to whom the GPO applies.
For those of you who insist that they really want CMD instead of PowerShell, you can simply set the value of that registry item to one (1) instead of zero (0). Or let users manually control it. But as I've been saying for years: "Death to CMD". :)