Tuesday, 18 September 2012

Enable-GUI.ps1

  1. <#
  2. .SYNOPSIS
  3. This script defines a function, Enable-Gui which
  4. enables the GUI on Windows Server 2012 Server Core
  5. .DESCRIPTION
  6. The Enable-GUI function enables the Gui in Server 2012
  7. Server Core by adding in two windows features. The
  8. script removes any Shell setting to ensure that when
  9. Server 2012 restarts, it starts with the full Desktop.
  10. .NOTES
  11. File Name : Enable-GUI.ps1
  12. Author : Thomas Lee - tfl@psp.co.uk
  13. Requires : PowerShell Version 3.0 and Windows Server 2012.
  14. .LINK
  15. This script posted to:
  16. http://www.pshscripts.blogspot.com
  17. .EXAMPLE
  18. Psh> Enable-GUI -Verbose
  19. Installing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra
  20. Removing Shell Registry Setting
  21. Finished installation, now rebooting
  22. < after reboot, full GUI is added >
  23. #>
  24. Function Enable-GUI {
  25. # No parameters - but maybe later
  26. # Turn on CmdletBinding to enable -Verbose
  27. [Cmdletbinding()]
  28. Param()
  29. # Install the GUI
  30. Write-Verbose "Installing Windows Feature: Server-GUI-Shell, Server-Gui-Mgmt-Infra"
  31. Install-WindowsFeature Server-Gui-Shell, Server-Gui-Mgmt-Infra -Source d:\sources\sxs
  32. # Remove the Setting For Shell to force back to CMD.EXE
  33. Write-Verbose 'Removing Shell Registry Setting'
  34. $RegPath = "Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon"
  35. Remove-ItemProperty -Confirm -Path $RegPath -Name Shell -ErrorAction SilentlyContinue
  36. # And reboot the system
  37. Write-Verbose "Finished installation, now rebooting"
  38. Restart-Computer
  39. }

3 comments:

Me said...

Using ISO from MS Volume Licensing for Server Core 2012, I had to specify the Source parameter as follows to access the features:

-Sources wim:D:\sources\install.wim,4

Me said...

Using the ISO from MS Volume Licensing for Server Enterprise Core 2012, I had to use the following Sources parameter to access the features for the GUI:

-Source wim:D:\sources\install.wim,4

Thomas Lee said...

As ME points out, sometimes the binaries for the desktop are excluded from what's oh disk, and yes you may need to specify a sources parameter so Windows can find the binaries. If you use Get-WindowsFeature - you can see whether a particular feature is on disk or not.