Skip to content

Instantly share code, notes, and snippets.

@PCfromDC
Last active November 29, 2017 23:04
Show Gist options
  • Save PCfromDC/b49762784f3d54b3e314 to your computer and use it in GitHub Desktop.
Save PCfromDC/b49762784f3d54b3e314 to your computer and use it in GitHub Desktop.
sp2016 Enable Windows Features
#region Create Server 2012R2 Features Array
function getServer2012R2Features {
$windows2012R2Features = @(
"Application-Server",
"AS-NET-Framework",
"AS-Web-Support",
"FileAndStorage-Services",
"Storage-Services",
"Web-Server",
"Web-WebServer",
"Web-Common-Http",
"Web-Default-Doc",
"Web-Dir-Browsing",
"Web-Http-Errors",
"Web-Static-Content",
"Web-Http-Redirect",
"Web-Health",
"Web-Http-Logging",
"Web-Log-Libraries",
"Web-Request-Monitor",
"Web-Performance",
"Web-Stat-Compression",
"Web-Dyn-Compression",
"Web-Security",
"Web-Filtering",
"Web-Basic-Auth",
"Web-Client-Auth",
"Web-Digest-Auth",
"Web-Cert-Auth",
"Web-IP-Security",
"Web-Url-Auth",
"Web-Windows-Auth",
"Web-App-Dev",
"Web-Net-Ext",
"Web-Net-Ext45",
"Web-Asp-Net45",
"Web-ISAPI-Ext",
"Web-ISAPI-Filter",
"Web-Mgmt-Tools",
"Web-Mgmt-Console",
"Web-Mgmt-Compat",
"Web-Metabase",
"Web-Lgcy-Mgmt-Console",
"Web-Lgcy-Scripting",
"Web-WMI",
"Web-Scripting-Tools",
"NET-Framework-Features",
"NET-Framework-Core",
"NET-HTTP-Activation",
"NET-Non-HTTP-Activ",
"NET-Framework-45-Features",
"NET-Framework-45-Core",
"NET-Framework-45-ASPNET",
"NET-WCF-Services45",
"NET-WCF-HTTP-Activation45",
"NET-WCF-TCP-PortSharing45",
"FS-SMB1",
"User-Interfaces-Infra",
"Server-Gui-Mgmt-Infra",
"Server-Gui-Shell",
"Windows-Identity-Foundation",
"PowerShellRoot",
"PowerShell",
"PowerShell-V2",
"PowerShell-ISE",
"WAS",
"WAS-Process-Model",
"WAS-NET-Environment",
"WAS-Config-APIs",
"WoW64-Support"
)
return $windows2012R2Features
}
#endregion
#region Create Server 2016 Features Array
function getServer2016Features ($sku) {
$windows2016Features = @(
"FileAndStorage-Services"
"Storage-Services",
"Web-Server",
"Web-WebServer",
"Web-Common-Http",
"Web-Default-Doc",
"Web-Dir-Browsing",
"Web-Http-Errors",
"Web-Static-Content",
"Web-Health",
"Web-Http-Logging",
"Web-Log-Libraries",
"Web-Request-Monitor",
"Web-Http-Tracing",
"Web-Performance",
"Web-Stat-Compression",
"Web-Dyn-Compression",
"Web-Security",
"Web-Filtering",
"Web-Basic-Auth",
"Web-Client-Auth",
"Web-Digest-Auth",
"Web-Cert-Auth",
"Web-IP-Security",
"Web-Url-Auth",
"Web-Windows-Auth",
"Web-App-Dev",
"Web-Net-Ext",
"Web-Net-Ext45",
"Web-Asp-Net",
"Web-Asp-Net45",
"Web-ISAPI-Ext",
"Web-ISAPI-Filter",
"Web-Mgmt-Tools",
"Web-Mgmt-Console",
"Web-Mgmt-Compat",
"Web-Metabase",
"Web-Lgcy-Scripting",
"Web-WMI",
"NET-Framework-Features",
"NET-Framework-Core",
"NET-HTTP-Activation",
"NET-Non-HTTP-Activ",
"NET-Framework-45-Features",
"NET-Framework-45-Core",
"NET-Framework-45-ASPNET",
"NET-WCF-Services45",
"NET-WCF-HTTP-Activation45",
"NET-WCF-Pipe-Activation45",
"NET-WCF-TCP-PortSharing45",
"Server-Media-Foundation",
"FS-SMB1",
"Windows-Identity-Foundation",
"PowerShellRoot",
"PowerShell",
"PowerShell-V2",
"PowerShell-ISE",
"WAS",
"WAS-Process-Model",
"WAS-NET-Environment",
"WAS-Config-APIs",
"WoW64-Support",
"XPS-Viewer"
)
# if OS is Enterprise
if ($sku -eq 10) {
$windows2016Features += ("InkAndHandwritingServices",
"User-Interfaces-Infra",
"Server-Gui-Mgmt-Infra",
"Desktop-Experience",
"Server-Gui-Shell",
"Windows-Server-Antimalware-Features",
"Windows-Server-Antimalware"
)
}
return $windows2016Features
}
#endregion
#region Get Server OS Information
function setEnvironment {
# Get OS Version Information
$serverOS = ([environment]::OSVersion.Version)
# Enterprise or Standard
$OS = (Get-WmiObject -ComputerName $env:COMPUTERNAME -Class Win32_OperatingSystem)
$sku = $OS.OperatingSystemSKU
# Server 2016
if ($serverOS.Major -eq "10") {
$windowsFeatures = @()
$windowsFeatures = getServer2016Features -sku $sku
$OS = $OS.Caption
Write-Host("Adding features for $OS...")
}
# Server 2012R2
if ($serverOS.Major -eq "6") {
$windowsFeatures = @()
$windowsFeatures = getServer2012R2Features
$OS = (Get-WmiObject -ComputerName $env:COMPUTERNAME -Class Win32_OperatingSystem).Caption
Write-Host("Adding features for $OS...")
}
# Add Windows Features
$restart = Add-WindowsFeature (ForEach-Object{$windowsFeatures})
if ($restart.RestartNeeded -ne "No") {
#if reboot required...
restartComputer
}
}
#endregion
#region Reboot Server
function restartComputer {
for ($i = 10; $i -gt 0; $i--) {
Write-Host("$env:COMPUTERNAME will reboot in $i seconds")
Start-Sleep -Seconds 1
}
Restart-Computer -Force
}
#endregion
#region Call Functions
setEnvironment
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment