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.  
  35. if ((Get-WindowsOptionalfeature -online -Feature Server-GUI-Shell).state -eq 'Enabled'){ 
  36.   "Server-GUI Shell is already enabled" 
  37. } 
  38.  
  39. if ((Get-WindowsOptionalfeature -online -Feature Server-Gui-Mgmt).state -eq 'Enabled'){ 
  40.   "Server-Gui-Mgmt is already enabled" 
  41. } 
  42.  
  43. # Enable the features needed to add the GUI 
  44. Enable-WindowsOptionalFeature –Online -NoRestart ` 
  45.       -Featurename ServerCore-FullServer, Server-Gui-Shell,Server-Gui-Mgmt 
  46.  
  47. # So Restart the computer 
  48. Restart-computer 
  49. } 
  50.  
  51. Function Disable-ServerCoreGui { 
  52.  
  53. #    Import the module 
  54. Import-Module -Name DISM -ErrorAction Stop 
  55.  
  56. # Disable all the features needed to add the GUI 
  57. # if any are already disabled, oh well - they're still disabled. 
  58. Disable-WindowsOptionalFeature –Online -NoRestart ` 
  59.       -Featurename ServerCore-FullServer, Server-Gui-Shell,Server-Gui-Mgmt 
  60.  
  61. # Finally Restart the computer 
  62. Restart-computer 
  63. } 

No comments: