Advertisement
Guest User

CoresightSquaredFeatures

a guest
Jul 28th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2.     .SYNOPSIS
  3.         Check for and install server roles and features for PI Coresight.
  4.        
  5.     .DESCRIPTION
  6.         The intent of this script is to check for, and optionally install all roles related to PI Coresight.
  7.         By default, optional roles are installed, but customers can elect to install only required features.
  8.  
  9.     .PARAMETER Mode
  10.         Determines whether the script will install missing roles and features or just list them (Install or List).
  11.         DEFAULT: List
  12.  
  13.     .PARAMETER RequiredOnly
  14.         Determines whether recommended roles and features are ignored. ($true or $false)
  15.         DEFAULT: $false
  16.  
  17.     .EXAMPLE
  18.         PS C:\Utilities\Scripts\Reporting> .\PICSCheckRolesFeatures.ps1 -Mode List -RequiredOnly $true
  19.  
  20.     .NOTES
  21.  
  22.         Last Modified: 28-July-2016
  23.        
  24. #>
  25. [CmdletBinding()]
  26. param (      
  27.        #OPTIONAL
  28.        [Parameter(Mandatory=$false)]
  29.        [ValidateSet('List','Install')]
  30.        [String] $Mode="List",
  31.        [Parameter(Mandatory=$false)]
  32.        [bool] $RequiredOnly = $false,
  33.        [Parameter(Mandatory=$false)]
  34.        [bool] $IsCore = $false
  35.       )
  36. begin
  37.     {
  38.     #region Load ActiveDirectory module if it is not loaded.
  39.         $ModuleName = "ServerManager"
  40.         if(-not(Get-Module -name $ModuleName))
  41.             {
  42.                 "{0}: Importing module {1}" -f (Get-Date), $ModuleName
  43.                 try {
  44.                         Import-Module -Name $ModuleName
  45.                         "{0}: Module {1} imported successfully" -f (Get-Date), $ModuleName
  46.                     }
  47.                 catch
  48.                     {
  49.                         "{0}: ERROR! Module {1} not imported successfully!" -f (Get-Date), $ModuleName
  50.                         exit
  51.                     }  
  52.             }
  53.         else {  
  54.                 "{0}: Module {1} already loaded" -f (Get-Date), $ModuleName
  55.              }
  56.     #endregion
  57.     }
  58. process
  59.       {      
  60.     #Check OS
  61.     $OSVersion = (Get-WmiObject -class Win32_OperatingSystem).Caption
  62.     "{0} detected." -f $OSVersion
  63.  
  64.     # Create arrays with required, optional and server 2012 features.
  65.         if ($IsCore) {
  66.         $features = @("WAS-Process-Model","WAS-NET-Environment", "WAS-Config-APIs", "NET-Framework-Core",
  67.         "NET-Http-Activation", "NET-Non-Http-Activ", "Web-WebServer", "Web-Static-Content", "Web-Default-Doc",
  68.         "Web-Net-Ext", "Web-Windows-Auth", "Web-Filtering", "Web-Url-Auth",  
  69.         "Web-Stat-Compression", "Web-Dyn-Compression")
  70.         $optionalfeatures = @()
  71.         $2012features = @("Web-Net-Ext45", "Web-Asp-Net45")
  72.         }
  73.         else
  74.         {
  75.         $features = @("WAS-Process-Model","WAS-NET-Environment", "WAS-Config-APIs", "NET-Framework-Core",
  76.         "NET-Http-Activation", "NET-Non-Http-Activ", "Web-WebServer", "Web-Static-Content", "Web-Default-Doc",
  77.         "Web-Http-Errors", "Web-Net-Ext", "Web-Windows-Auth", "Web-Filtering", "Web-Url-Auth", "Web-Basic-Auth",
  78.         "Web-Stat-Compression", "Web-Dyn-Compression", "Web-Mgmt-Console",
  79.         "Application-Server", "AS-Net-Framework", "AS-HTTP-Activation", "AS-Web-Support")
  80.         $optionalfeatures = @("Web-Http-Redirect", "Web-Asp-Net", "Web-ISAPI-Ext", "Web-ISAPI-Filter",
  81.         "Web-Http-Logging", "Web-Log-Libraries", "Web-Request-Monitor", "Web-Http-Tracing", "Web-Client-Auth",
  82.         "Web-Digest-Auth", "Web-Cert-Auth", "Web-IP-Security", "Web-Scripting-Tools", "Web-Mgmt-Service")
  83.         $2012features = @("NET-Framework-45-Core", "NET-WCF-HTTP-Activation45", "Web-Net-Ext45", "Web-Asp-Net45")
  84.         }
  85.  
  86.     # Concatenate feature lists as appropriate
  87.         if ($OSVersion -like '*2012*') {$features += $2012features}
  88.         if ($RequiredOnly -eq $false) {$features += $optionalfeatures}
  89.         $total = $features.Length
  90.         $i = 0
  91.         $count = 0
  92.     foreach ($feature in $features)
  93.         {
  94.         "{0} of {1}: {2}" -f ++$i, $total, $feature
  95.         $featureObj = Get-WindowsFeature -name $feature
  96.         [string]$name = $featureObj.DisplayName
  97.        
  98.         if (!$featureObj.Installed) {
  99.             "{0} NOT INSTALLED." -f $name
  100.             $count++
  101.             if ($Mode -eq "Install") {
  102.                 "Attempting to install {0}."  -f $name
  103.                 try {
  104.                 Add-WindowsFeature -name $feature
  105.                 "{0} installed successfully!" -f $name
  106.                 }
  107.                 catch {"ERROR installing {0}" -f $name}
  108.  
  109.             }
  110.        
  111.             }
  112.         }      
  113.       }
  114. end
  115. {
  116.     "{0} missing roles or features found" -f $count
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement