Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Check for and install server roles and features for PI Coresight.
- .DESCRIPTION
- The intent of this script is to check for, and optionally install all roles related to PI Coresight.
- By default, optional roles are installed, but customers can elect to install only required features.
- .PARAMETER Mode
- Determines whether the script will install missing roles and features or just list them (Install or List).
- DEFAULT: List
- .PARAMETER RequiredOnly
- Determines whether recommended roles and features are ignored. ($true or $false)
- DEFAULT: $false
- .EXAMPLE
- PS C:\Utilities\Scripts\Reporting> .\PICSCheckRolesFeatures.ps1 -Mode List -RequiredOnly $true
- .NOTES
- Last Modified: 28-July-2016
- #>
- [CmdletBinding()]
- param (
- #OPTIONAL
- [Parameter(Mandatory=$false)]
- [ValidateSet('List','Install')]
- [String] $Mode="List",
- [Parameter(Mandatory=$false)]
- [bool] $RequiredOnly = $false,
- [Parameter(Mandatory=$false)]
- [bool] $IsCore = $false
- )
- begin
- {
- #region Load ActiveDirectory module if it is not loaded.
- $ModuleName = "ServerManager"
- if(-not(Get-Module -name $ModuleName))
- {
- "{0}: Importing module {1}" -f (Get-Date), $ModuleName
- try {
- Import-Module -Name $ModuleName
- "{0}: Module {1} imported successfully" -f (Get-Date), $ModuleName
- }
- catch
- {
- "{0}: ERROR! Module {1} not imported successfully!" -f (Get-Date), $ModuleName
- exit
- }
- }
- else {
- "{0}: Module {1} already loaded" -f (Get-Date), $ModuleName
- }
- #endregion
- }
- process
- {
- #Check OS
- $OSVersion = (Get-WmiObject -class Win32_OperatingSystem).Caption
- "{0} detected." -f $OSVersion
- # Create arrays with required, optional and server 2012 features.
- if ($IsCore) {
- $features = @("WAS-Process-Model","WAS-NET-Environment", "WAS-Config-APIs", "NET-Framework-Core",
- "NET-Http-Activation", "NET-Non-Http-Activ", "Web-WebServer", "Web-Static-Content", "Web-Default-Doc",
- "Web-Net-Ext", "Web-Windows-Auth", "Web-Filtering", "Web-Url-Auth",
- "Web-Stat-Compression", "Web-Dyn-Compression")
- $optionalfeatures = @()
- $2012features = @("Web-Net-Ext45", "Web-Asp-Net45")
- }
- else
- {
- $features = @("WAS-Process-Model","WAS-NET-Environment", "WAS-Config-APIs", "NET-Framework-Core",
- "NET-Http-Activation", "NET-Non-Http-Activ", "Web-WebServer", "Web-Static-Content", "Web-Default-Doc",
- "Web-Http-Errors", "Web-Net-Ext", "Web-Windows-Auth", "Web-Filtering", "Web-Url-Auth", "Web-Basic-Auth",
- "Web-Stat-Compression", "Web-Dyn-Compression", "Web-Mgmt-Console",
- "Application-Server", "AS-Net-Framework", "AS-HTTP-Activation", "AS-Web-Support")
- $optionalfeatures = @("Web-Http-Redirect", "Web-Asp-Net", "Web-ISAPI-Ext", "Web-ISAPI-Filter",
- "Web-Http-Logging", "Web-Log-Libraries", "Web-Request-Monitor", "Web-Http-Tracing", "Web-Client-Auth",
- "Web-Digest-Auth", "Web-Cert-Auth", "Web-IP-Security", "Web-Scripting-Tools", "Web-Mgmt-Service")
- $2012features = @("NET-Framework-45-Core", "NET-WCF-HTTP-Activation45", "Web-Net-Ext45", "Web-Asp-Net45")
- }
- # Concatenate feature lists as appropriate
- if ($OSVersion -like '*2012*') {$features += $2012features}
- if ($RequiredOnly -eq $false) {$features += $optionalfeatures}
- $total = $features.Length
- $i = 0
- $count = 0
- foreach ($feature in $features)
- {
- "{0} of {1}: {2}" -f ++$i, $total, $feature
- $featureObj = Get-WindowsFeature -name $feature
- [string]$name = $featureObj.DisplayName
- if (!$featureObj.Installed) {
- "{0} NOT INSTALLED." -f $name
- $count++
- if ($Mode -eq "Install") {
- "Attempting to install {0}." -f $name
- try {
- Add-WindowsFeature -name $feature
- "{0} installed successfully!" -f $name
- }
- catch {"ERROR installing {0}" -f $name}
- }
- }
- }
- }
- end
- {
- "{0} missing roles or features found" -f $count
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement