PoshCode Archive  Artifact [7047a05372]

Artifact 7047a053723232fd7384b0f18bccda70230506709882ae342a8bec7ff6b335c9:

  • File Change-Server-2012-type.ps1 — part of check-in [70dd0c997f] at 2018-06-10 13:31:21 on branch trunk — With the ablity to change between core, minimal, and GUI as the interface with Windows Server 2012, I put this together to make it easy to switch between the different types. It will install or uninstall the necessary features to get to state that you supply the script. (user: Na_pope size: 3294)

# encoding: ascii
# api: powershell
# title: Change Server 2012 type
# description: With the ablity to change between core, minimal, and GUI as the interface with Windows Server 2012, I put this together to make it easy to switch between the different types.  It will install or uninstall the necessary features to get to state that you supply the script.
# version: 0.1
# type: script
# author: Na_pope
# license: CC0
# x-poshcode-id: 3804
# x-archived: 2013-01-10T07:16:19
# x-published: 2013-11-29T15:27:00
#
# Convert-Win2012ServerType -Type Core
#
<#
.SYNOPSIS
Use this script to change Windows Server 2012 to 1 of 4 types.  The script installs or uninstalls
windows features to get to the desired type.  The 4 types are:
Core - just a commandline
Minimal - commandline with added binaries to run some MMCs and Server Manager
Full GUI - standard desktop look with all GUI tools
RemoteDesktop - Add the desktop experience pack to be used in a Remote Desktop farm setting.

.DESCRIPTION
Convert-Win2012ServerType -Type (Core, Min, Gui, RemoteDesktop)

.PARAMETER Type
Choose one of the following - Core, Min, Gui, RemoteDesktop

.Notes
	* Author  - Nate Pope
	* Date	  - 11/28/2012
	* Version - .3
.EXAMPLE
To convert to a core install:
Convert-Win2012ServerType -Type Core

Convert to a GUI install:
Convert-Win2012ServerType -Type GUI

 #>
 param(
 [Parameter(Mandatory=$true)]
 [String[]]$Type
 )
 
Function InstallMask {
$InstallMask = 0
if ((get-windowsfeature server-gui-mgmt-infra).installed) {
	$InstallMask += 1
}
if ((get-windowsfeature server-gui-Shell).installed) {
	$InstallMask += 2
}
if ((get-windowsfeature Desktop-Experience).installed) {
	$InstallMask += 4
}
return $InstallMask
}

Function Covert2Core($mask) {
if ($mask -eq 0){ 
Write-Verbose "Already Core"
return
}
$inst = uninstall-windowsFeature -Name Desktop-Experience, server-gui-Shell, server-gui-mgmt-infra 

return $inst.RestartNeeded
}

Function Covert2Min($mask) {
if ($mask -eq 1){ 
Write-Verbose "Already Min"
return
}else {
uninstall-windowsFeature -name server-gui-shell, desktop-Experience 
}
$inst = install-windowsFeature server-gui-mgmt-infra
return $inst.RestartNeeded
}

Function Covert2Gui($mask) {
if ($mask -eq 3){ 
Write-Verbose "Already Full Gui"
return
}elseif ($mask -gt 4 ) {
uninstall-windowsFeature -name Desktop-Experience
}
$inst = install-windowsFeature -Name server-gui-Shell, server-gui-mgmt-infra
return $inst.RestartNeeded
}

Function Covert2RD($mask) {
if ($mask -eq 7){ 
Write-Verbose "Already Remote Desktop "
return
}
$inst = install-windowsFeature -Name Desktop-Experience, server-gui-Shell, server-gui-mgmt-infra
return $inst.RestartNeeded
}

 
########################################################################################################### 
 

 $mask = InstallMask
 switch ($Type) {
	Core {
		$reboot = Covert2Core($mask)
		break
	}
	Min {
		$reboot = Covert2Min($mask)
		break
	}
	Gui {
		$reboot = Covert2Gui($mask)
		break
	}
	RemoteDesktop {
		$reboot = Covert2RD($mask)
		break
	}
	default {
		Write-Warning "The TYPE parameter must be specified (Core, Min, Gui, or RemoteDesktop)"
		break
	}
}
if ($reboot) { Restart-Computer }