Thursday 5 July 2012

Manage-ServerCoreGui.ps1

  1. <# 
  2. .Synopsis 
  3.    This file contains two simple functions to manage the GUI
  4.    in Server Core Windows Server 2012. 
  5. .DESCRIPTION 
  6.    There are two functions: Enable-ServerCoreGui that enables
  7.    the GUI in a server core installation. Diable-ServerCoreGuI
  8.    disables the GUI and returns the installation to
  9.    traditional Server Core. 
  10.  
  11.    Enable-ServerCoreGui also checks to see if some or all
  12.    parts are already installed andwarns accordingly. 
  13. .EXAMPLE 
  14.    c:\foo> Enable-ServerCoreGui 
  15.     
  16.    This enables the GUI and reboots the Server into FUll GUI mode. 
  17.  
  18. .EXAMPLE 
  19.    c:\foo> Disable-ServerCoreGui 
  20.     
  21.    This disables the GUI and reboots the Server back to Server Core mode. 
  22. #> 
  23.  
  24.  
  25. Function Enable-ServerCoreGui { 
  26.  
  27. #    Import the module 
  28. Import-Module -Name DISM -ErrorAction Stop 
  29.  
  30. # is it already enabled?? 
  31. if ((Get-WindowsOptionalfeature -online -Feature ServerCore-FullServer).state -eq 'Enabled'){ 
  32.   "Servercore-FullServer is already enabled" 
  33.  
  34. if ((Get-WindowsOptionalfeature -online -Feature Server-GUI-Shell).state -eq 'Enabled'){ 
  35.   "Server-GUI Shell is already enabled" 
  36.  
  37. if ((Get-WindowsOptionalfeature -online -Feature Server-Gui-Mgmt).state -eq 'Enabled'){ 
  38.   "Server-Gui-Mgmt is already enabled" 
  39.  
  40. # Enable the features needed to add the GUI 
  41. Enable-WindowsOptionalFeature –Online -NoRestart ` 
  42.       -Featurename ServerCore-FullServer, Server-Gui-Shell,Server-Gui-Mgmt 
  43.  
  44. # So Restart the computer 
  45. Restart-computer 
  46.  
  47. Function Disable-ServerCoreGui { 
  48.  
  49. #    Import the module 
  50. Import-Module -Name DISM -ErrorAction Stop 
  51.  
  52. # Disable all the features needed to add the GUI 
  53. # if any are already disabled, oh well - they're still disabled. 
  54. Disable-WindowsOptionalFeature –Online -NoRestart ` 
  55.       -Featurename ServerCore-FullServer, Server-Gui-Shell,Server-Gui-Mgmt 
  56.  
  57. # Finally Restart the computer 
  58. Restart-computer